refactor: simplify error handling and reporting#226
Conversation
64a6f2c to
5ae52a8
Compare
Collapse the 17-branch `catch` dispatcher in `src/index.ts` into a single flow: a pure `formatError` maps a known error to its user-facing message, tracking fires once, and only unknown errors reach Sentry. Segment now records the error message on every failed command. Reword the Type Builder requirement message and link to the repository's settings page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
acb1f83 to
682e15d
Compare
| }, | ||
| body, | ||
| signal: AbortSignal.timeout(2_000), | ||
| }); |
There was a problem hiding this comment.
Sentry ingest failures ignored silently
Medium Severity
sentryCaptureError awaits the envelope fetch but never checks whether the response succeeded. Non-2xx or malformed-ingest replies are swallowed by the outer try/catch, so unexpected CLI errors may never reach Sentry despite the refactor’s goal of reporting them.
Reviewed by Cursor Bugbot for commit 682e15d. Configure here.
| JSON.stringify({ event_id: eventId, sent_at: new Date().toISOString() }), | ||
| JSON.stringify({ type: "event" }), | ||
| JSON.stringify(event), | ||
| ].join("\n"); |
There was a problem hiding this comment.
Sentry envelope missing item length
High Severity
The hand-built Sentry envelope posts an event item header with only type, but Relay expects each item header to include the payload byte length. Ingest can reject the body, and failures are swallowed, so unexpected CLI errors may never reach Sentry after removing the SDK.
Reviewed by Cursor Bugbot for commit 682e15d. Configure here.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d0301ab. Configure here.
| This command requires the Type Builder in your repository. | ||
|
|
||
| Enable it by turning off Legacy Builder in your repository settings: | ||
| https://${error.repo}.${error.host}/settings/repository/ |
There was a problem hiding this comment.
Wrong repository settings URL
Medium Severity
The Type Builder error links to https://{repo}.{host}/settings/repository/, but repository settings elsewhere use app/settings/repository on the same host (e.g. wroom.ts, integration tests). Users following the link may hit a missing or wrong page instead of repository settings.
Reviewed by Cursor Bugbot for commit d0301ab. Configure here.


Resolves:
Description
Simplifies the error handling and reporting in
src/index.ts. Thecatchblock was 17 near-identicalinstanceofbranches, each repeating the same tracking boilerplate and differing only in the message printed.formatErrormaps a known error to its user-facing message (orundefinedfor an unexpected one).Also refactors
src/lib/sentry.tsto drop the@sentry/node-coreSDK. It now builds and POSTs the Sentry envelope directly viafetch, removing the dependency.Checklist
Preview
How to QA 1
🤖 Generated with Claude Code
Note
Medium Risk
Replacing the Sentry SDK with a hand-rolled ingest path and changing when errors are reported vs tracked could alter production error visibility; behavior is limited to CLI telemetry and user messaging.
Overview
Consolidates CLI failure handling in
src/index.ts: a newformatErrormaps known errors to user-facing text,trackCommandEndruns once per failed command (with the formatted message when available), and Sentry is only invoked for unexpected errors that are rethrown.src/lib/sentry.tsno longer uses@sentry/node-core; it builds a minimal Sentry envelope and POSTs it withfetch, withsetupSentrytaking explicit DSN/app metadata from the entrypoint. The@sentry/node-coredevDependency and related lockfile entries are removed.TypeBuilderRequiredErrornow carriesrepoandhostso the message can link tohttps://{repo}.{host}/settings/repository/;initpasses those values when Type Builder is not enabled.Reviewed by Cursor Bugbot for commit d0301ab. Bugbot is set up for automated code reviews on this repo. Configure here.
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩