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

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

Merged
merged 1 commit into from
Jan 20, 2022
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
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(
petebacondarwin marked this conversation as resolved.
Show resolved Hide resolved
`${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;
}
}