Skip to content

Commit

Permalink
feat: add a link to create a github issue when there is an error.
Browse files Browse the repository at this point in the history
When a (non-yargs) error surfaces to the top level,
we know also show a link to Github to encourage the developer to report an issue.
  • Loading branch information
petebacondarwin committed Jan 20, 2022
1 parent 5fcef05 commit e9ab55a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .changeset/modern-beers-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": patch
---

feat: add a link to create a github issue when there is an error.

When a (non-yargs) error surfaces to the top level,
we know also show a link to Github to encourage the developer to report an issue.
45 changes: 30 additions & 15 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,12 @@ describe("wrangler", () => {
`kv:key put key value --binding otherBinding`
);
expect(stdout).toMatchInlineSnapshot(`""`);
expect(stderr).toMatchInlineSnapshot(
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
);
expect(stderr).toMatchInlineSnapshot(`
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
%s
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
`);
expect(error).toMatchInlineSnapshot(
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
);
Expand All @@ -668,9 +671,12 @@ describe("wrangler", () => {
"kv:key put my-key my-value --binding someBinding"
);
expect(stdout).toMatchInlineSnapshot(`""`);
expect(stderr).toMatchInlineSnapshot(
`"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
);
expect(stderr).toMatchInlineSnapshot(`
"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
%s
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
`);
expect(error).toMatchInlineSnapshot(
`[Error: someBinding has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.]`
);
Expand Down Expand Up @@ -814,9 +820,12 @@ describe("wrangler", () => {
expect(error).toMatchInlineSnapshot(
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
);
expect(stderr).toMatchInlineSnapshot(
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
);
expect(stderr).toMatchInlineSnapshot(`
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
%s
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
`);
expect(stdout).toMatchInlineSnapshot(`""`);
});
});
Expand Down Expand Up @@ -1001,9 +1010,12 @@ describe("wrangler", () => {
`kv:key get key --binding otherBinding`
);
expect(stdout).toMatchInlineSnapshot(`""`);
expect(stderr).toMatchInlineSnapshot(
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
);
expect(stderr).toMatchInlineSnapshot(`
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
%s
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
`);
expect(error).toMatchInlineSnapshot(
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
);
Expand Down Expand Up @@ -1061,9 +1073,12 @@ describe("wrangler", () => {
const { stderr } = await runWrangler(
`kv:key delete --binding otherBinding someKey`
);
expect(stderr).toMatchInlineSnapshot(
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
);
expect(stderr).toMatchInlineSnapshot(`
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
%s
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
`);
});

it("should delete a key in a namespace specified by binding name in a given environment", async () => {
Expand Down
12 changes: 11 additions & 1 deletion packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import { setTimeout } from "node:timers/promises";
import * as fs from "node:fs";
import { execa } from "execa";

const resetColor = "\x1b[0m";
const fgGreenColor = "\x1b[32m";

async function readConfig(configPath?: string): Promise<Config> {
const config: Config = {};
if (!configPath) {
Expand Down Expand Up @@ -1911,8 +1914,15 @@ export async function main(argv: string[]): Promise<void> {
if (e instanceof CommandLineArgsError) {
wrangler.showHelp("error");
console.error(""); // Just adds a bit of space
console.error(e.message);
} else {
console.error(e.message);
console.error(""); // Just adds a bit of space
console.error(
`${fgGreenColor}%s${resetColor}`,
"If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
);
}
console.error(e.message);
throw e;
}
}

0 comments on commit e9ab55a

Please sign in to comment.