Skip to content

refactor: simplify error handling and reporting#226

Open
angeloashmore wants to merge 4 commits into
aa/refactorfrom
aa/error-handling
Open

refactor: simplify error handling and reporting#226
angeloashmore wants to merge 4 commits into
aa/refactorfrom
aa/error-handling

Conversation

@angeloashmore

@angeloashmore angeloashmore commented Jul 15, 2026

Copy link
Copy Markdown
Member

Resolves:

Description

Simplifies the error handling and reporting in src/index.ts. The catch block was 17 near-identical instanceof branches, each repeating the same tracking boilerplate and differing only in the message printed.

  • A pure formatError maps a known error to its user-facing message (or undefined for an unexpected one).
  • Tracking fires once. Segment now records the error message on every failed command; Sentry stays scoped to unexpected errors only.
  • Reworded the Type Builder requirement message and linked to the repository's settings page.

Also refactors src/lib/sentry.ts to drop the @sentry/node-core SDK. It now builds and POSTs the Sentry envelope directly via fetch, removing the dependency.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1

🤖 Generated with Claude Code


Note

Medium Risk
Custom Sentry ingestion may miss SDK behaviors (sampling, breadcrumbs), and the new rule to report some UnknownRequestError cases to Sentry changes observability for handled network failures.

Overview
Refactors CLI failure handling so one catch path formats messages, prints them, ends tracking, and decides Sentry reporting instead of many duplicated instanceof branches.

formatError centralizes user-facing copy for known errors; unexpected errors stay undefined so the stack is rethrown. trackCommandEnd now always runs on failure and passes the formatted message (or raw error) into Segment. Sentry is limited to unhandled errors and UnknownRequestError cases without a server message.

TypeBuilderRequiredError now carries repo and host; init and the formatter point users at the repository settings URL to disable Legacy Builder instead of the prior rollout wording.

@sentry/node-core is removed. setupSentry takes explicit config from index.ts; sentry.ts keeps tags/context in memory and POSTs a minimal Sentry envelope via fetch (stack parsing, 2s timeout, silent failures).

Reviewed by Cursor Bugbot for commit ffd3889. Bugbot is set up for automated code reviews on this repo. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

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>
@angeloashmore angeloashmore marked this pull request as ready for review July 15, 2026 01:50
Comment thread src/index.ts
Comment thread src/lib/sentry.ts
Comment thread src/lib/sentry.ts
Comment thread src/index.ts Outdated
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread src/index.ts
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e40fbf8. Configure here.

Comment thread src/index.ts
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant