diff --git a/.changeset/modern-beers-repair.md b/.changeset/modern-beers-repair.md new file mode 100644 index 000000000000..057194d4d842 --- /dev/null +++ b/.changeset/modern-beers-repair.md @@ -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. diff --git a/packages/wrangler/src/__tests__/kv.test.ts b/packages/wrangler/src/__tests__/kv.test.ts index 56a8d5493e69..f6c48ca55a49 100644 --- a/packages/wrangler/src/__tests__/kv.test.ts +++ b/packages/wrangler/src/__tests__/kv.test.ts @@ -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".]` ); @@ -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.]` ); @@ -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(`""`); }); }); @@ -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".]` ); @@ -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 () => { diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index 53b2dfc45aee..7b68ef780980 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -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 { const config: Config = {}; if (!configPath) { @@ -1911,8 +1914,15 @@ export async function main(argv: string[]): Promise { 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; } }