Skip to content

fix(api): strip api/0/ prefix and exclude NodeSystemError integration (CLI-K1)#523

Merged
BYK merged 5 commits intomainfrom
fix/cli-k1-api-prefix-system-error
Mar 23, 2026
Merged

fix(api): strip api/0/ prefix and exclude NodeSystemError integration (CLI-K1)#523
BYK merged 5 commits intomainfrom
fix/cli-k1-api-prefix-system-error

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Mar 23, 2026

Fixes two bugs surfaced by CLI-K1:

1. Double /api/0/ prefix in sentry api command

When users include the /api/0/ prefix in the endpoint argument (e.g. sentry api /api/0/projects/my-org/my-project/environments/), the URL construction doubled it to /api/0/api/0/.... normalizeEndpoint() now strips the prefix automatically.

2. util.getSystemErrorMap() crash on Bun

The Sentry SDK's NodeSystemError integration calls util.getSystemErrorMap() which Bun does not implement, causing the SDK's event processing pipeline to crash with a TypeError. This integration is now excluded from the default integrations set — it only adds extra context for Node.js system errors and is not needed for CLI telemetry.

…CLI-K1)

Two bugs caused CLI-K1:

1. normalizeEndpoint() did not strip api/0/ prefix when users included it
   in the endpoint argument (e.g. 'sentry api /api/0/projects/...'),
   producing doubled paths like /api/0/api/0/...

2. The Sentry SDK's NodeSystemError integration calls
   util.getSystemErrorMap() which Bun does not implement, crashing the
   SDK's event processing pipeline.

Fix: strip api/0/ prefix in normalizeEndpoint(), exclude NodeSystemError
from default integrations.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 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).


Bug Fixes 🐛

  • (api) Strip api/0/ prefix and exclude NodeSystemError integration (CLI-K1) by BYK in #523
  • (dashboard) Add missing datasets to agent guidance by betegon in #522
  • (event) Auto-redirect issue short IDs in event view (CLI-JR) by BYK in #524

Internal Changes 🔧

  • Regenerate skill files by github-actions[bot] in 22b5281d

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 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 92.86%. Project has 1076 uncovered lines.
✅ Project coverage is 95.79%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
telemetry.ts 91.30% ⚠️ 41 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.79%    95.79%        —%
==========================================
  Files          185       185         —
  Lines        25557     25569       +12
  Branches         0         0         —
==========================================
+ Hits         24482     24493       +11
- Misses        1075      1076        +1
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK marked this pull request as ready for review March 23, 2026 12:26
…e api/0?query

- Emit log.warn when stripping the api/0/ prefix so users know it happened
- Patch NodeSystemError integration with try-catch instead of excluding it,
  so system error context is still captured on runtimes that support it
- Handle api/0?query edge case (query string without trailing slash)
- Add tests for the api/0?query variant
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 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Try-catch won't catch errors from async processEvent
    • Wrapped processEvent return value with Promise.resolve().catch() to handle both synchronous throws and asynchronous rejections from async functions.

Create PR

Or push these changes by commenting:

@cursor push 1e12ec0a94
Preview (1e12ec0a94)
diff --git a/src/lib/telemetry.ts b/src/lib/telemetry.ts
--- a/src/lib/telemetry.ts
+++ b/src/lib/telemetry.ts
@@ -287,7 +287,9 @@
 
   integration.processEvent = (...args) => {
     try {
-      return original(...args);
+      const result = original(...args);
+      // Handle both sync throws and async rejections
+      return Promise.resolve(result).catch(() => args[0]);
     } catch {
       // getSystemErrorMap is not available — skip enrichment, keep the event
       return args[0];

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

…emErrorMap upfront

- Remove api/0? query-string edge case (reviewer: clearly an error)
- Replace try-catch patch with upfront hasGetSystemErrorMap check at
  module load — conditionally excludes NodeSystemError integration
  when util.getSystemErrorMap is missing (Bun)
- Move the api/0/ prefix warning from normalizeEndpoint (pure function)
  to the command's func() to avoid polluting stderr during unit tests
- Remove api/0? query-string edge case per reviewer feedback
- Replace try-catch SDK patch with upfront hasGetSystemErrorMap check
  at module load — excludes NodeSystemError when method is missing
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 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

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

Replace duplicated api/0/ detection condition in func() with a
length comparison against normalizeEndpoint's output. Since the
function only adds at most 1 char (trailing slash), a shorter
result indicates the prefix was stripped.
@BYK BYK merged commit b02a6d0 into main Mar 23, 2026
22 checks passed
@BYK BYK deleted the fix/cli-k1-api-prefix-system-error branch March 23, 2026 13:30
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