From e8aaa39307f44e974c3ab966e7880f50a5ff6bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Wed, 15 Jan 2025 12:31:50 +0000 Subject: [PATCH] Unwrap SDW errors before sending to Sentry (#7735) * Unwrap SDW errors before sending to Sentry * Create honest-spies-prove.md * Update .changeset/honest-spies-prove.md Co-authored-by: Pete Bacon Darwin * Less assigning * Fix typing issues --------- Co-authored-by: Pete Bacon Darwin --- .changeset/honest-spies-prove.md | 5 +++++ packages/wrangler/src/index.ts | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .changeset/honest-spies-prove.md diff --git a/.changeset/honest-spies-prove.md b/.changeset/honest-spies-prove.md new file mode 100644 index 000000000000..6020acffae53 --- /dev/null +++ b/.changeset/honest-spies-prove.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Unwrap the error cause when available to send to Sentry diff --git a/packages/wrangler/src/index.ts b/packages/wrangler/src/index.ts index b5d1795b64e4..361614f6e247 100644 --- a/packages/wrangler/src/index.ts +++ b/packages/wrangler/src/index.ts @@ -1006,6 +1006,7 @@ export async function main(argv: string[]): Promise { cliHandlerThrew = true; let mayReport = true; let errorType: string | undefined; + let loggableException = e; logger.log(""); // Just adds a bit of space if (e instanceof CommandLineArgsError) { @@ -1071,7 +1072,6 @@ export async function main(argv: string[]): Promise { errorType = "BuildFailure"; logBuildFailure(e.cause.errors, e.cause.warnings); } else { - let loggableException = e; if ( // Is this a StartDevEnv error event? If so, unwrap the cause, which is usually the user-recognisable error e && @@ -1102,13 +1102,12 @@ export async function main(argv: string[]): Promise { // Only report the error if we didn't just handle it mayReport && // ...and it's not a user error - !(e instanceof UserError) && + !(loggableException instanceof UserError) && // ...and it's not an un-reportable API error - !(e instanceof APIError && !e.reportable) + !(loggableException instanceof APIError && !loggableException.reportable) ) { - await captureGlobalException(e); + await captureGlobalException(loggableException); } - const durationMs = Date.now() - startTime; dispatcher?.sendCommandEvent(