Skip to content

Commit

Permalink
Unwrap SDW errors before sending to Sentry (#7735)
Browse files Browse the repository at this point in the history
* Unwrap SDW errors before sending to Sentry

* Create honest-spies-prove.md

* Update .changeset/honest-spies-prove.md

Co-authored-by: Pete Bacon Darwin <[email protected]>

* Less assigning

* Fix typing issues

---------

Co-authored-by: Pete Bacon Darwin <[email protected]>
  • Loading branch information
penalosa and petebacondarwin authored Jan 15, 2025
1 parent 713f4e8 commit e8aaa39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-spies-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Unwrap the error cause when available to send to Sentry
9 changes: 4 additions & 5 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ export async function main(argv: string[]): Promise<void> {
cliHandlerThrew = true;
let mayReport = true;
let errorType: string | undefined;
let loggableException = e;

logger.log(""); // Just adds a bit of space
if (e instanceof CommandLineArgsError) {
Expand Down Expand Up @@ -1071,7 +1072,6 @@ export async function main(argv: string[]): Promise<void> {
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 &&
Expand Down Expand Up @@ -1102,13 +1102,12 @@ export async function main(argv: string[]): Promise<void> {
// 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(
Expand Down

0 comments on commit e8aaa39

Please sign in to comment.