Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

fix(error-reporting): silence ContextError to stop crash reports (CLI-3B) - #1149

Merged
BYK merged 1 commit into
mainfrom
byk/fix/silence-context-error
Jun 26, 2026
Merged

BYK merged 1 commit into
mainfrom
byk/fix/silence-context-error

Conversation

@BYK

@BYK BYK commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

ContextError is thrown when the user omits a required value — no
org/project could be auto-detected, a required ID was not provided, etc. It is
an expected user-input error (per AGENTS.md: "User omitted a required value →
ContextError"
), yet it was still reported to Sentry as an unhandled crash.

That made it the single highest-volume issue in the project:

Issue Title Users Events
CLI-3B Could not auto-detect organization and project 1985 9003
CLI-CG Event ID is required 619 1618
CLI-1BC Specific project is required 133 291
CLI-1BD Span ID is required 90 194

Fix

Classify ContextError as silenced in classifySilenced, mirroring the
existing OutputError / expected-AuthError / 401–499 ApiError rules:

  • Volume is preserved via the cli.error.silenced metric, now enriched with the
    ContextError.resource so the missing value (e.g. "Organization and project" vs "Event ID") keeps sub-grouping context. resource values are a
    small fixed set, so metric cardinality stays low.
  • Silenced errors also no longer mark the session as crashed, so missing-input
    errors stop skewing release-health.

Why the whole class (vs. opt-in like ResolutionError)

ContextError always means "you didn't provide X" — there is nothing
per-instance to investigate. This differs from ResolutionError, where a
provided value that can't be matched may signal a product/access issue worth
observing (which is why that class is silenced opt-in). The cli.error.silenced
metric still records the volume and which value was missing.

Test plan

  • classifySilenced tests updated: ContextError now asserts "context_missing"
    (removed from the "does NOT silence" list).
  • reportCliError integration: ContextError now asserts no captureException
    • a cli.error.silenced metric carrying error_class, reason, resource.
  • telemetry test updated: ContextError is silenced and does not mark the
    session crashed.
  • vitest run test/lib/error-reporting.test.ts test/lib/telemetry.test.ts → 183 passed
  • property + session telemetry suites → 65 passed
  • biome check clean on changed files

Fixes CLI-3B

)

ContextError is thrown when the user omits a required value — no
org/project could be auto-detected, a required ID was not provided, etc.
It is an expected user-input error, never a CLI bug, yet it was still
reported to Sentry as an unhandled crash. This made it the single
highest-volume issue (CLI-3B: ~2000 users / ~9000 events, plus CLI-CG,
CLI-1BC, CLI-1BD).

Classify ContextError as silenced in classifySilenced, mirroring the
existing OutputError / expected-AuthError / 4xx-ApiError rules. Volume is
preserved via the cli.error.silenced metric, now enriched with the
ContextError resource so the missing value (e.g. "Organization and
project" vs "Event ID") keeps sub-grouping context.

Unlike ResolutionError — where a provided-but-unmatched value can signal
a product/access issue worth observing — ContextError has nothing
per-instance to investigate, so the whole class is silenced. Silenced
errors also no longer mark the session as crashed, which keeps
release-health from being skewed by missing-input errors.
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1149/

Built to branch gh-pages at 2026-06-26 20:01 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 5133 uncovered lines.
❌ Project coverage is 81.46%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    81.53%    81.46%    -0.07%
==========================================
  Files          397       397         —
  Lines        27682     27686        +4
  Branches     17968     17972        +4
==========================================
+ Hits         22570     22553       -17
- Misses        5112      5133       +21
- Partials      1867      1861        -6

Generated by Codecov Action

@BYK
BYK merged commit 795e3b8 into main Jun 26, 2026
28 checks passed
@BYK
BYK deleted the byk/fix/silence-context-error branch June 26, 2026 20:12
BYK added a commit that referenced this pull request Jul 14, 2026
…o-detect error (#1155)

## Why

Follow-up to #1149 based on review feedback: **"Could not auto-detect
organization and project" was being silenced, which hid the signal AND
skipped the underlying UX fix.** We keep these errors around to learn
where users get stuck — so the right move is to help users succeed *and*
keep the error visible to measure impact.

CLI-3B: ~2000 users.

## What changed

**1. Sole-account auto-select (helps every command, zero risk)**
`resolveOrgAndProject` gains a final cascade step: when an authenticated
account has exactly **one** accessible org with exactly **one** project,
that pair is the only possible answer, so it's returned instead of
`null`. This is strictly additive — callers that depend on a `null`
return (notably `event view`'s cross-org search) are unaffected, since
it only ever turns a `null` into a uniquely-determined target.

**2. Interactive picker (TTY)**
On a failed auto-detect, `guideOrgProjectFailure` prompts the user to
choose an org then a project, and saves the choice as the default (so
they're not asked again). Gated on **both** stdin and stdout being TTYs,
so piped/`--json` invocations never block on a prompt.

**3. Enriched error**
Authenticated users who still can't be resolved get a `ContextError`
listing their accessible orgs (copy-pasteable), instead of the generic
"run `sentry org list`" guidance shown to logged-out users.

**4. Un-silence `ContextError`**
Reverted the `classifySilenced` `ContextError` branch (and the now-dead
`recordSilencedError` resource attribute) so its volume stays visible —
that volume is the signal for whether the UX changes above actually
work.

## Wiring

`guideOrgProjectFailure` is invoked on the auto-detect failure path of
`resolveOrgProjectTarget`, `resolveTargetsFromParsedArg` (backs `issue
list`), and `trace-target`. The fallback is kept **separate** from
`resolveOrgAndProject` (rather than wrapping it) so command tests that
mock the resolver — and rely on its `null` return — keep working; the
guide only runs on the explicit failure path.

Upload commands
(`sourcemap`/`debug-files`/`proguard`/`code-mappings`/`dart-symbol-map`)
get the sole-account auto-select for free via `resolveOrgAndProject`;
their interactive-picker/enriched-error wiring can follow up (they're
usually non-interactive CI runs with DSN/config context).

## Tests

- `resolveOrgProjectOrGuide`: sole-org/project auto-select, multi-org
enriched `ContextError`, unauthenticated generic `ContextError` (no
org-list call).
- Updated `classifySilenced` / `recordSilencedError` / telemetry tests
to assert `ContextError` is now **captured**, not silenced.
- Updated trace/span resolver tests for the new fallback path.
- Full `test/lib` + `test/commands` suites green (7964 passing); lint +
typecheck clean.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant