Skip to content

Commit b1a21ac

Browse files
authored
Merge pull request #376 from vim-denops/fix-call-batch-error-message
👍 Remove `args` from error messages of `call/batch`
2 parents fec75b9 + 30b47a3 commit b1a21ac

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

denops/@denops-private/host.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,3 @@ export function invoke(
9191
throw new Error(`Service does not have a method '${name}'`);
9292
}
9393
}
94-
95-
export function formatCall(fn: string, ...args: unknown[]): string {
96-
return `${fn}(${args.map((v) => JSON.stringify(v)).join(", ")})`;
97-
}

denops/@denops-private/host/nvim.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "https://deno.land/x/messagepack_rpc@v2.0.3/mod.ts";
66
import { errorDeserializer, errorSerializer } from "../error.ts";
77
import { getVersionOr } from "../version.ts";
8-
import { formatCall, Host, invoke, Service } from "../host.ts";
8+
import { Host, invoke, Service } from "../host.ts";
99

1010
export class Neovim implements Host {
1111
#session: Session;
@@ -63,9 +63,7 @@ export class Neovim implements Host {
6363
if (isNvimErrorObject(err)) {
6464
const [code, message] = err;
6565
throw new Error(
66-
`Failed to call ${
67-
formatCall(fn, ...args)
68-
}: ${message} (code: ${code})`,
66+
`Failed to call '${fn}' in Neovim: ${message} (code: ${code})`,
6967
);
7068
}
7169
throw err;
@@ -82,11 +80,10 @@ export class Neovim implements Host {
8280
const [ret, err] = ensure(result, isNvimCallAtomicReturn);
8381
if (err) {
8482
const [index, code, message] = err;
83+
const fn = calls[index][0];
8584
return [
8685
ret,
87-
`Failed to call ${
88-
formatCall(...calls[index])
89-
}: ${message} (code: ${code})`,
86+
`Failed to call '${fn}' in Neovim: ${message} (code: ${code})`,
9087
];
9188
}
9289
return [ret, ""];

denops/@denops-private/host/nvim_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Deno.test("Neovim", async (t) => {
6767
await assertRejects(
6868
() => host.call("@@@@@", -4),
6969
Error,
70-
"Failed to call @@@@@(-4): Vim:E117: Unknown function: @@@@@ (code: 0)",
70+
"Failed to call '@@@@@' in Neovim: Vim:E117: Unknown function: @@@@@ (code: 0)",
7171
);
7272
},
7373
);
@@ -93,7 +93,7 @@ Deno.test("Neovim", async (t) => {
9393
assertEquals(ret, [4, 10]);
9494
assertMatch(
9595
err,
96-
/Failed to call @@@@@\(-9\): Vim:E117: Unknown function: @@@@@/,
96+
/Failed to call '@@@@@' in Neovim: Vim:E117: Unknown function: @@@@@/,
9797
);
9898
},
9999
);

denops/@denops-private/host/vim.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Message,
55
Session,
66
} from "https://deno.land/x/vim_channel_command@v3.0.0/mod.ts";
7-
import { formatCall, Host, invoke, Service } from "../host.ts";
7+
import { Host, invoke, Service } from "../host.ts";
88

99
export class Vim implements Host {
1010
#session: Session;
@@ -53,7 +53,7 @@ export class Vim implements Host {
5353
}
5454
const [ret, err] = ensure(result, isCallReturn);
5555
if (err !== "") {
56-
throw new Error(`Failed to call ${formatCall(fn, ...args)}: ${err}`);
56+
throw new Error(`Failed to call '${fn}' in Vim: ${err}`);
5757
}
5858
return ret;
5959
}
@@ -72,9 +72,10 @@ export class Vim implements Host {
7272
const [ret, err] = ensure(result, isBatchReturn) as [unknown[], string];
7373
if (err) {
7474
const index = ret.length;
75+
const fn = calls[index][0];
7576
return [
7677
ret,
77-
`Failed to call ${formatCall(...calls[index])}: ${err}`,
78+
`Failed to call '${fn}' in Vim: ${err}`,
7879
];
7980
}
8081
return [ret, ""];

denops/@denops-private/host/vim_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Deno.test("Vim", async (t) => {
7070
await assertRejects(
7171
() => host.call("@@@@@", -4),
7272
Error,
73-
"Failed to call @@@@@(-4): Vim(let):E117: Unknown function: @@@@@",
73+
"Failed to call '@@@@@' in Vim: Vim(let):E117: Unknown function: @@@@@",
7474
);
7575
},
7676
);
@@ -96,7 +96,7 @@ Deno.test("Vim", async (t) => {
9696
assertEquals(ret, [4, 10]);
9797
assertMatch(
9898
err,
99-
/Failed to call @@@@@\(-9\): Vim\(.*\):E117: Unknown function: @@@@@/,
99+
/Failed to call '@@@@@' in Vim: Vim\(.*\):E117: Unknown function: @@@@@/,
100100
);
101101
},
102102
);

0 commit comments

Comments
 (0)