Conversation
…eady configured When `sentry init .` is run in a project with an existing Sentry DSN, the CLI was extracting the numeric org ID (e.g. `4507492088676352`) from the DSN and passing it directly to the API as an org slug. If the org belonged to a different Sentry account (or the org regions cache was empty after a fresh install), this caused a confusing 404 error: "Organization '4507492088676352' not found." Fix the numeric ID fallback in `resolveOrgFromDsn`: instead of returning the raw numeric ID, look it up in the org regions cache via `getOrgByNumericId`. If found, use the real slug. If not (empty cache or inaccessible org), return null so the caller falls through to `listOrganizations()` for proper interactive org selection. Also add a UX improvement: before creating a new Sentry project, detect whether the codebase already has a Sentry DSN that resolves to an accessible project. If so, prompt the user: "Found an existing Sentry project. Use it or create a new one?" This avoids silently creating a duplicate project when Sentry is already configured. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Event
Other
Documentation 📚
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1024 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.81% 96.02% +0.21%
==========================================
Files 185 185 —
Lines 25681 25757 +76
Branches 0 0 —
==========================================
+ Hits 24605 24733 +128
- Misses 1076 1024 -52
- Partials 0 0 —Generated by Codecov Action |
The previous fix to resolveOrgFromDsn was too broad — returning null broke DSN org auto-detection for read commands like `sentry issue list` that work fine with numeric org IDs. Revert resolveOrgFromDsn to its original behavior. Instead, handle the numeric ID resolution in resolveOrgSlug (local-ops.ts), which is only used by sentry init's project creation path. When the prefetched org is a raw numeric string, attempt to resolve it to a slug via the org regions cache (getOrgByNumericId). On cache miss — empty cache or org from a different Sentry account — fall through to listOrganizations() so the user can select from their accessible orgs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ect detection Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract `promptForExistingProject` helper to reduce cognitive complexity - Move numeric org ID regex to top-level constant - Wrap single-statement if-returns in block statements - Simplify double-negation logical expression - Fix import ordering and template literals in test file - Apply formatter line-wrapping Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reuse `resolveDsnByPublicKey` from resolve-target.ts instead of duplicating the getCachedProjectByDsnKey → findProjectByDsnKey → setCachedProjectByDsnKey pattern. Addresses cursor bot review comment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…error formatting Errors thrown by tryGetExistingProject (e.g. non-404 ApiErrors) now reach formatLocalOpError instead of bubbling up as raw error.message strings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Bug fix (sentry init only): When `sentry init .` is run in a project with an existing Sentry DSN, the CLI extracts a numeric org ID (e.g. `4507492088676352`) from the DSN. If the org belonged to a different Sentry account, or the org regions cache was empty after a fresh install, this numeric ID was passed directly to `listTeams()` → 404 → confusing error: "Organization '4507492088676352' not found."
Fix scoped to `resolveOrgSlug` in `local-ops.ts` (only used by sentry init): when the prefetched org is a raw numeric string, look it up in the org regions cache (`getOrgByNumericId`). If found → use the real slug. If not (empty cache or inaccessible org) → fall through to `listOrganizations()` so the user selects from their accessible orgs.
UX improvement: Before creating a new project, `sentry init` now checks if the codebase already has a Sentry DSN that resolves to an accessible project. If so, prompts: "Found an existing Sentry project (org/project). Use it or create a new one?" — avoids silently creating a duplicate when Sentry is already configured.
Scope: no impact on other commands
The numeric ID fallback in `resolveOrgFromDsn` is intentionally unchanged. Commands like `sentry issue list`, `sentry trace view`, and `sentry event view` rely on DSN org auto-detection and work correctly with numeric IDs (the Sentry API accepts them for read operations). Only `sentry init`'s project-creation path gets the narrower fix.
How the original bug was triggered
Fresh CLI install → `sentry auth login` (`warmOrgCache()` fires in background, may not complete before process exits) → immediately `sentry init .` in a project with a Sentry DSN → empty org regions cache → numeric org ID used directly → 404.
Test plan
🤖 Generated with Claude Code