Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👍 Remove args from error messages of call/batch #376

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions denops/@denops-private/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,3 @@ export function invoke(
throw new Error(`Service does not have a method '${name}'`);
}
}

export function formatCall(fn: string, ...args: unknown[]): string {
return `${fn}(${args.map((v) => JSON.stringify(v)).join(", ")})`;
}
11 changes: 4 additions & 7 deletions denops/@denops-private/host/nvim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "https://deno.land/x/[email protected]/mod.ts";
import { errorDeserializer, errorSerializer } from "../error.ts";
import { getVersionOr } from "../version.ts";
import { formatCall, Host, invoke, Service } from "../host.ts";
import { Host, invoke, Service } from "../host.ts";

export class Neovim implements Host {
#session: Session;
Expand Down Expand Up @@ -63,9 +63,7 @@ export class Neovim implements Host {
if (isNvimErrorObject(err)) {
const [code, message] = err;
throw new Error(
`Failed to call ${
formatCall(fn, ...args)
}: ${message} (code: ${code})`,
`Failed to call '${fn}' in Neovim: ${message} (code: ${code})`,
);
}
throw err;
Expand All @@ -82,11 +80,10 @@ export class Neovim implements Host {
const [ret, err] = ensure(result, isNvimCallAtomicReturn);
if (err) {
const [index, code, message] = err;
const fn = calls[index][0];
return [
ret,
`Failed to call ${
formatCall(...calls[index])
}: ${message} (code: ${code})`,
`Failed to call '${fn}' in Neovim: ${message} (code: ${code})`,
];
}
return [ret, ""];
Expand Down
4 changes: 2 additions & 2 deletions denops/@denops-private/host/nvim_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Deno.test("Neovim", async (t) => {
await assertRejects(
() => host.call("@@@@@", -4),
Error,
"Failed to call @@@@@(-4): Vim:E117: Unknown function: @@@@@ (code: 0)",
"Failed to call '@@@@@' in Neovim: Vim:E117: Unknown function: @@@@@ (code: 0)",
);
},
);
Expand All @@ -93,7 +93,7 @@ Deno.test("Neovim", async (t) => {
assertEquals(ret, [4, 10]);
assertMatch(
err,
/Failed to call @@@@@\(-9\): Vim:E117: Unknown function: @@@@@/,
/Failed to call '@@@@@' in Neovim: Vim:E117: Unknown function: @@@@@/,
);
},
);
Expand Down
7 changes: 4 additions & 3 deletions denops/@denops-private/host/vim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Message,
Session,
} from "https://deno.land/x/[email protected]/mod.ts";
import { formatCall, Host, invoke, Service } from "../host.ts";
import { Host, invoke, Service } from "../host.ts";

export class Vim implements Host {
#session: Session;
Expand Down Expand Up @@ -53,7 +53,7 @@ export class Vim implements Host {
}
const [ret, err] = ensure(result, isCallReturn);
if (err !== "") {
throw new Error(`Failed to call ${formatCall(fn, ...args)}: ${err}`);
throw new Error(`Failed to call '${fn}' in Vim: ${err}`);
}
return ret;
}
Expand All @@ -72,9 +72,10 @@ export class Vim implements Host {
const [ret, err] = ensure(result, isBatchReturn) as [unknown[], string];
if (err) {
const index = ret.length;
const fn = calls[index][0];
return [
ret,
`Failed to call ${formatCall(...calls[index])}: ${err}`,
`Failed to call '${fn}' in Vim: ${err}`,
];
}
return [ret, ""];
Expand Down
4 changes: 2 additions & 2 deletions denops/@denops-private/host/vim_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Deno.test("Vim", async (t) => {
await assertRejects(
() => host.call("@@@@@", -4),
Error,
"Failed to call @@@@@(-4): Vim(let):E117: Unknown function: @@@@@",
"Failed to call '@@@@@' in Vim: Vim(let):E117: Unknown function: @@@@@",
);
},
);
Expand All @@ -96,7 +96,7 @@ Deno.test("Vim", async (t) => {
assertEquals(ret, [4, 10]);
assertMatch(
err,
/Failed to call @@@@@\(-9\): Vim\(.*\):E117: Unknown function: @@@@@/,
/Failed to call '@@@@@' in Vim: Vim\(.*\):E117: Unknown function: @@@@@/,
);
},
);
Expand Down