Skip to content

feat(telemetry): report unknown commands to Sentry#563

Merged
BYK merged 2 commits intomainfrom
feat/report-unknown-commands
Mar 26, 2026
Merged

feat(telemetry): report unknown commands to Sentry#563
BYK merged 2 commits intomainfrom
feat/report-unknown-commands

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Mar 25, 2026

When Stricli's route scanner rejects an unrecognized subcommand (e.g.,
sentry issue helpp), it handles the error internally — writing to stderr
and setting exitCode to 251 (UnknownCommand) without throwing. This means
the error was invisible to Sentry telemetry.

Adds reportUnknownCommand() inside runCommand (within the withTelemetry
scope) that detects ExitCode.UnknownCommand after run() completes and
reports via Sentry.captureMessage() with rich context:

  • User context: Already set by initTelemetryContext() in the
    withTelemetry scope — user ID, email, instance ID, runtime, etc.
  • Org context: Default organization from SQLite cache (no API call)
  • Fuzzy suggestions: Runs resolveCommandPath() from the introspection
    system to find the unknown token and fuzzy-matched alternatives
  • Full argv: For pattern analysis

This covers nested route typos like sentry issue helpp or
sentry dashboard creat. Top-level typos like sentry isseu list are
routed through the help command's fuzzy matching via defaultCommand: "help".

Changes

  • src/bin.ts: Import ExitCode, add reportUnknownCommand() that
    detects unknown command exit code, walks the route tree for fuzzy
    suggestions, reads default org from SQLite, and captures a Sentry
    message event with structured context.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Dashboard

  • Add pagination and glob filtering to dashboard list by BYK in #560
  • Rich terminal chart rendering for dashboard view by BYK in #555

Other

  • (formatters) Colorize SQL in DB span descriptions by BYK in #546
  • (init) Treat bare slug as new project name when not found by BYK in #554
  • (telemetry) Report unknown commands to Sentry by BYK in #563
  • Add sentry sourcemap inject and sentry sourcemap upload commands by BYK in #547
  • Native debug ID injection and sourcemap upload by BYK in #543

Bug Fixes 🐛

Dashboard

  • Scale timeseries bar width to fill chart area by BYK in #562
  • Resolve dashboard by ID/slug in addition to title by BYK in #559

Other

  • (event-view) Auto-redirect issue short IDs in two-arg form (CLI-MP) by BYK in #558
  • (help) Show help when user passes help as positional arg by BYK in #561
  • Reject @-selectors in parseOrgProjectArg with helpful redirect by BYK in #557

Internal Changes 🔧

Coverage

  • Use informational-patch input instead of sed hack by BYK in #544
  • Make checks informational on release branches by BYK in #541

Other

  • (api) Collapse stats on issue detail endpoints to save 100-300ms by BYK in #551
  • (ci) Upgrade GitHub Actions to Node 24 runtime by BYK in #542
  • (db) DRY up database layer with shared helpers and lint enforcement by BYK in #550
  • (issue-list) Use collapse parameter to skip unused Snuba queries by BYK in #545
  • Bump Bun from 1.3.9 to 1.3.11 by BYK in #552
  • Regenerate skill files by github-actions[bot] in ec1ffe28

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1271 uncovered lines.
✅ Project coverage is 95.4%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.40%    95.40%        —%
==========================================
  Files          194       194         —
  Lines        27655     27655         —
  Branches         0         0         —
==========================================
+ Hits         26384     26384         —
- Misses        1271      1271         —
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK force-pushed the feat/report-unknown-commands branch 3 times, most recently from 53b77a2 to 26807a5 Compare March 25, 2026 20:00
@BYK BYK marked this pull request as ready for review March 25, 2026 20:03
@BYK BYK force-pushed the feat/report-unknown-commands branch from 26807a5 to 448f031 Compare March 25, 2026 20:12
When Stricli's route scanner rejects an unrecognized subcommand (e.g.,
`sentry issue helpp`) it handles the error internally — writing to
stderr and setting exitCode to 251 without throwing. This means the
error was invisible to Sentry telemetry.

Add `reportUnknownCommand()` inside `runCommand` (within the
`withTelemetry` scope) that detects `ExitCode.UnknownCommand` after
`run()` completes and reports via `Sentry.captureMessage()` with:

- `command` tag set to `"unknown"` for filtering
- `sentry.org` tag from default organization (SQLite, no API call)
- `unknown_command` context with full argv, the unknown token,
  fuzzy suggestions from the introspection system, and default org
- User context (already set by `initTelemetryContext` in the
  `withTelemetry` scope)
@BYK BYK force-pushed the feat/report-unknown-commands branch from c2d30ca to 3e70280 Compare March 25, 2026 23:36
@BYK BYK force-pushed the feat/report-unknown-commands branch from 3e70280 to 5ecbd27 Compare March 25, 2026 23:49
Copy link
Copy Markdown

@cursor cursor bot left a comment

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 and found 2 potential issues.

Fix All in Cursor

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

…sitive argv

Address two Bugbot findings:

1. High: reportUnknownCommand performs dynamic imports, route resolution,
   and SQLite reads without error handling. Exceptions would propagate
   through withTelemetry's catch block, marking the session as crashed
   and overriding the UnknownCommand exit code. Fix: wrap the call in
   try/catch so telemetry failures are silently ignored.

2. Medium: raw argv was sent to Sentry context without redacting
   --token values. Add redactArgv() that replaces values following
   sensitive flags (--token, --auth-token) with [REDACTED] in both
   --flag=value and --flag <value> forms. Uses SENSITIVE_ARGV_FLAGS set
   mirroring SENSITIVE_FLAGS from telemetry.ts.

Extracted sensitiveArgvFlag() helper to stay under Biome's cognitive
complexity limit of 15.
@BYK BYK force-pushed the feat/report-unknown-commands branch from 5ecbd27 to 33dd92d Compare March 25, 2026 23:57
@BYK BYK merged commit 78e2a20 into main Mar 26, 2026
22 checks passed
@BYK BYK deleted the feat/report-unknown-commands branch March 26, 2026 00:10
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