Repository navigation
fix(cli): List the only organization when no project is detected (CLI-3B) - #1947
Merged
Merged
Conversation
…-3B) When auto-detection finds no org or project and the account can reach exactly one organization, use that organization: - issue list lists it org-wide, like `sentry issue list <org>/` - org-scoped commands (explore, replay, ...) resolve to it Several orgs still get the existing guidance error. Nothing is saved as a default. Co-Authored-By: Miguel Betegon <miguel.betegon@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
betegon
self-requested a review
November 4, 2026 16:29
BYK
pushed a commit
that referenced
this pull request
Nov 4, 2026
…1958) Follow-up to #1947. That PR added the "use the only accessible org" fallback at two call sites (`resolveOrgOnlyTarget`, `resolveOrgOptionalTarget`). This PR moves it into the shared `resolveOrg` cascade instead. It becomes step 6, after DSN detection, the same way `resolveOrgAndProject` already falls back to the only org/project at its step 7. With that change, every command that resolves its org through `resolveOrg` gets the fallback. That includes issue `@latest` / `@most_frequent` and text search, `trace view`, `event view`, and org positionals (`orgTarget`). It still applies only when you are authenticated, have exactly one accessible org, and no org is configured or detected. ### Before ``` $ sentry issue view @latest Error: Could not auto-detect organization. Provide it explicitly: sentry issue view <org>/@latest Or: - Run from a directory with a Sentry DSN in source code or .env files - Set SENTRY_ORG and SENTRY_PROJECT (or SENTRY_DSN) environment variables - Run 'sentry org list' to find your organization slug - Run 'sentry project list <org>/' to find project slugs ``` ### After ``` $ sentry issue view @latest WEB-1A: TypeError: Cannot read properties of undefined ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ╭────────────┬───────────────────────────────────╮ │ Status │ ● Unresolved (Ongoing) │ │ Priority │ High │ │ Level │ error │ │ Platform │ javascript │ │ Project │ web (web) │ │ Events │ 42 │ │ Users │ 7 │ │ … │ │ ╰────────────┴───────────────────────────────────╯ Tip: Use 'sentry issue explain @latest' for AI root cause analysis ``` Both outputs come from a local mock server with one org (`acme-corp`) and two projects. I trimmed some rows from the After table. ### Changes - `resolveOrg` falls back to `resolveSoleOrg()` after DSN detection, and the two call-site fallbacks are removed. - A DSN lookup that fails now falls through to the account fallback instead of returning `null`. `resolveOrgAndProject` already behaves this way. - Docs: adds step 7 to the resolution priority list in `configuration.md`. ### Testing - A new test checks that `resolveOrg` returns the only org. - Two tests asserted that no requests happen before a context error. They now allow the org list lookup (`/api/0/organizations/`) and still assert that no issue or share request is made. - `pnpm run tsc` and `pnpm run lint` pass. The focused suites pass: resolve-target, context-recovery, issue, trace, event, and trace-target (822 tests). In the full CLI run, the only failures are ones that also fail on `main` in my sandbox (permission and env checks). <!-- junior-request-attribution:start --> via @betegon. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0C615WFS9G%3A1793783849.302359 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0C615WFS9G%3A1793783849.302359) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0C615WFS9G%3A1793783849.302359/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Miguel Betegon <28983162+betegon@users.noreply.github.com>
7 tasks done
This branch was previously deployed
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.
Follow-up to #1938 for the "Could not auto-detect organization" error.
If an account can reach one organization that has several projects, commands still fail when nothing is detected from the working directory. The existing fallback only handles one org with one project.
When auto-detect finds nothing and the account has exactly one org:
issue listlists that org's issues, the same assentry issue list <org>/.explore,replay, …) use that org.Accounts with several orgs get the same guidance error as before. Defaults are never saved, and skipped self-hosted DSNs still show their own error.
Before
After
I captured this output against a local mock server with one org and two projects.
Testing
test/lib/context-recovery.test.tscover org-wideissue list, an org-only command, and the multi-org case that still errors. The first two fail without this change.pnpm run tscandpnpm run lintpass. In the full CLI unit run, the only failures are 11 that also fail onmainin my sandbox. They are permission and environment checks in completions, db/resilient, code-scanner, errors, file-changes, oauth, auto-login-host-guard, and upgrade.via bete.
--
View Session [Sentry]