Commit b14c22b
authored
## Summary
Fixes [CLI-1GC](https://sentry.sentry.io/issues/7444602558/): user runs
`sentry api ... --input /tmp/missing.json`, sees `Unexpected error:
Error: File not found: ...` with a full stack trace, and the error gets
captured to Sentry as a CLI bug.
## Root cause
`buildBodyFromInput()` in `src/commands/api.ts` throws a plain `new
Error()` when the `--input` file doesn't exist. Because this runs inside
the command's `func()` body (not a Stricli `parse` callback), it
bypasses the `CliError` handling chain in `app.ts`:
1. `classifySilenced()` doesn't recognize plain `Error` →
`Sentry.captureException` fires → reported as a CLI bug.
2. `exc instanceof CliError` is `false` → user sees `Unexpected error:`
+ stack trace instead of a clean message.
This is the same pattern documented in the lore entry _"api.ts: plain
Error throws inside func() bypass CliError handling"_ — same file, same
kind of bug across 7 call sites.
## Fix
Convert all 7 `func()`-path `throw new Error(...)` sites in
`src/commands/api.ts` to `throw new ValidationError(..., field)`:
| Function | `field` |
|----------|---------|
| `buildBodyFromInput` (file not found) | `"input"` |
| `parseHeaders` (bad header format) | `"header"` |
| `parseFieldKey` (bad key format) | `"field"` |
| `validatePathSegments` (dangerous/invalid keys) | `"field"` |
| `validateTypeCompatibility` (type conflicts) | `"field"` |
`parseMethod` (line 74) keeps `new Error()` — it runs in a Stricli
`parse` callback where Stricli catches and formats it.
After the fix:
- User sees a clean `Error: File not found: /tmp/missing.json` (no stack
trace).
- The error is silenced from Sentry telemetry as an expected user error.
- The `field` metadata enables stable Sentry grouping if any of these
surfaces do legitimately need attention.
## Test plan
- Updated existing `buildBodyFromInput` "throws for non-existent file"
test to assert `instanceof ValidationError`.
- `bun test test/commands/api.test.ts` — 203 pass.
- `bun test test/commands/api.property.test.ts` — 50 pass.
- `bun run lint`, `bun run typecheck` — clean.
1 parent 16e853b commit b14c22b
2 files changed
Lines changed: 21 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
198 | 201 | | |
199 | | - | |
200 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
201 | 205 | | |
202 | 206 | | |
203 | 207 | | |
| |||
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
252 | | - | |
253 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
254 | 259 | | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
258 | | - | |
259 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
260 | 266 | | |
261 | 267 | | |
262 | 268 | | |
| |||
628 | 634 | | |
629 | 635 | | |
630 | 636 | | |
631 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
632 | 641 | | |
633 | 642 | | |
634 | 643 | | |
| |||
821 | 830 | | |
822 | 831 | | |
823 | 832 | | |
824 | | - | |
| 833 | + | |
825 | 834 | | |
826 | 835 | | |
827 | 836 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1039 | 1039 | | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | | - | |
| 1042 | + | |
1043 | 1043 | | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
1047 | | - | |
| 1047 | + | |
1048 | 1048 | | |
1049 | 1049 | | |
1050 | 1050 | | |
| |||
0 commit comments