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

fix: suggest trying to update Wrangler if there is a newer one available after an unexpected error #5746

Merged
merged 1 commit into from
May 2, 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
5 changes: 5 additions & 0 deletions .changeset/stale-parrots-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: suggest trying to update Wrangler if there is a newer one available after an unexpected error
20 changes: 20 additions & 0 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { logPossibleBugMessage } from "..";
import { getPackageManager } from "../package-manager";
import { updateCheck } from "../update-check";
import { endEventLoop } from "./helpers/end-event-loop";
import { mockConsoleMethods } from "./helpers/mock-console";
import { runInTempDir } from "./helpers/run-in-tmp";
Expand Down Expand Up @@ -279,4 +281,22 @@ describe("wrangler", () => {
--dry-run: exiting now."
`);
});

describe("logPossibleBugMessage()", () => {
it("should display a 'possible bug' message", async () => {
await logPossibleBugMessage();
expect(std.out).toMatchInlineSnapshot(
`"If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"`
);
});

it("should display a 'try updating' message if there is one available", async () => {
(updateCheck as jest.Mock).mockImplementation(async () => "123.123.123");
await logPossibleBugMessage();
expect(std.out).toMatchInlineSnapshot(`
"If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
Note that there is a newer version of Wrangler available (123.123.123). Consider checking whether upgrading resolves this error."
`);
});
});
});
23 changes: 18 additions & 5 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
import { tailHandler, tailOptions } from "./tail";
import registerTriggersSubcommands from "./triggers";
import { typesHandler, typesOptions } from "./type-generation";
import { printWranglerBanner } from "./update-check";
import { printWranglerBanner, updateCheck } from "./update-check";
import {
getAuthFromEnv,
listScopes,
Expand Down Expand Up @@ -839,10 +839,7 @@ export async function main(argv: string[]): Promise<void> {
} else {
logger.error(e instanceof Error ? e.message : e);
if (!(e instanceof UserError)) {
logger.log(
`${fgGreenColor}%s${resetColor}`,
"If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
);
await logPossibleBugMessage();
}
}

Expand Down Expand Up @@ -910,4 +907,20 @@ export function getDevCompatibilityDate(
return compatibilityDate ?? currentDate;
}

/**
* Write a message to the log that tells the user what they might do after we have reported an unexpected error.
*/
export async function logPossibleBugMessage() {
logger.log(
`${fgGreenColor}%s${resetColor}`,
"If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
);
const latestVersion = await updateCheck();
if (latestVersion) {
logger.log(
`Note that there is a newer version of Wrangler available (${latestVersion}). Consider checking whether upgrading resolves this error.`
);
}
}

export { printWranglerBanner };
Loading