Skip to content

fix: add Glob.match() polyfill + improve auto-detect diagnostics (CLI-7T)#487

Merged
BYK merged 3 commits intomainfrom
fix/cli-7t-glob-polyfill-autodetect
Mar 19, 2026
Merged

fix: add Glob.match() polyfill + improve auto-detect diagnostics (CLI-7T)#487
BYK merged 3 commits intomainfrom
fix/cli-7t-glob-polyfill-autodetect

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Mar 19, 2026

Problem

When users run sentry issue list or sentry issues without explicit org/project arguments, the auto-detection cascade fails with ContextError: Organization and project are required. — 185 events affecting 63 users (CLI-7T).

100% of events are from the Node.js/npm distribution (cli.runtime: node), and 46% use --json (AI agents/tool callers).

Root cause

The BunGlobPolyfill class in the Node.js polyfill was missing the match() method. When anyGlobMatches() in project-root.ts called new Bun.Glob(pattern).match(name), it threw a TypeError that was silently swallowed by a bare catch {} block. This broke project root detection for .NET (*.sln, *.csproj), Haskell (*.cabal), OCaml (*.opam), and Nim (*.nimble) projects on the npm distribution.

While this bug is real, the primary cause for most users is simply running the CLI from a directory without a Sentry-instrumented project and with no env vars or config defaults set. The diagnostics and error message improvements help these users find the right path forward.

Fix

  1. Add match() to BunGlobPolyfill — Uses picomatch (already bundled via tinyglobby) with {dot: true} to match Bun.Glob behavior.

  2. Add debug logging to resolveAllTargets() — Each fallthrough step (env vars → config defaults → DSN detection → directory inference) now logs at debug level, visible with --verbose.

  3. Improve ContextError default alternatives — Adds sentry org list and sentry project list <org>/ hints so users who don't know their slugs have a clear next step.

Tests

  • 5 new tests for Glob.match() covering all LANGUAGE_MARKER_GLOBS patterns, negative cases, directory path rejection, and consistency with native Bun.Glob.match().
  • All existing tests pass. Typecheck and lint clean.

Fixes CLI-7T

)

Three fixes for CLI-7T (ContextError: Organization and project are required):

1. Add missing match() to BunGlobPolyfill (script/node-polyfills.ts)
   The Node.js polyfill only had scan() — calling match() threw TypeError,
   silently swallowed by a bare catch {} in anyGlobMatches(). This broke
   project root detection for .NET (*.sln, *.csproj), Haskell (*.cabal),
   OCaml (*.opam), and Nim (*.nimble) on the npm distribution. Uses
   picomatch with dot:true to match Bun.Glob behavior.

2. Add debug logging to resolveAllTargets() (src/lib/resolve-target.ts)
   Each fallthrough step now logs at debug level so users can diagnose
   auto-detection failures with --verbose.

3. Add actionable alternatives to ContextError defaults (src/lib/errors.ts)
   Adds 'sentry org list' and 'sentry project list <org>/' hints so
   users who don't know their slugs have a clear next step.

Fixes CLI-7T
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 19, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 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 ✨

  • (telemetry) Track TTY vs non-TTY invocations via metric by betegon in #482
  • Dynamic cache-backed shell completions with fuzzy matching by BYK in #465

Bug Fixes 🐛

  • (project) Fallback to org listing when bare slug matches an organization by betegon in #475
  • Add Glob.match() polyfill + improve auto-detect diagnostics (CLI-7T) by BYK in #487
  • Add org-slug pre-check to dispatchOrgScopedList (CLI-9A) by BYK in #485

Internal Changes 🔧

  • (issue) Skip getProject round-trip in project-search resolution by betegon in #473
  • (resolve) Carry project data through resolution to eliminate redundant getProject calls by BYK in #486
  • Switch from @sentry/bun to @sentry/node-core/light (~170ms startup savings) by BYK in #474
  • Regenerate skill files by github-actions[bot] in b7b240ec

🤖 This preview updates automatically when you update the PR.

@BYK BYK marked this pull request as ready for review March 19, 2026 23:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 19, 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 1037 uncovered lines.
✅ Project coverage is 95.77%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
resolve-target.ts 83.19% ⚠️ 117 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.77%    95.77%        —%
==========================================
  Files          180       180         —
  Lines        24520     24534       +14
  Branches         0         0         —
==========================================
+ Hits         23483     23497       +14
- Misses        1037      1037         —
- Partials         0         0         —

Generated by Codecov Action

Addresses Cursor BugBot review: picomatch was only available as a
transitive dependency via tinyglobby. Adding it explicitly prevents
breakage if tinyglobby ever changes its dependency tree.
Copy link
Copy Markdown
Contributor

@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 1 potential issue.

Fix All in Cursor

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

Addresses Cursor BugBot review: cache the compiled picomatch matcher
in the constructor instead of recompiling on every match() call.
Matches Bun.Glob semantics where the pattern is compiled once.
@BYK BYK merged commit 94382ba into main Mar 19, 2026
22 checks passed
@BYK BYK deleted the fix/cli-7t-glob-polyfill-autodetect branch March 19, 2026 23:46
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