Repository navigation
fix(cli): Use the org from an org auth token when none is set (CLI-3B) - #1938
Merged
Merged
Conversation
Org auth tokens (sntrys_) embed their organization, and legacy sentry-cli used it when --org/SENTRY_ORG was missing. The new CLI ignored it, so bundler-plugin and CI setups that pass only a token and a project failed with "Could not auto-detect organization". Fall back to the token's org right after SENTRY_ORG. Co-Authored-By: Miguel Betegon <miguel.betegon@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
BYK
approved these changes
Nov 4, 2026
BYK
left a comment
Member
There was a problem hiding this comment.
Interesting, I thought I've already done this earlier.
betegon
added a commit
that referenced
this pull request
Nov 4, 2026
…-3B) (#1947) 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 list` lists that org's issues, the same as `sentry issue list <org>/`. - Org-scoped commands (`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 ``` $ sentry issue list --limit 5 Error: Organization and project are required. Specify them using: sentry issue list <org>/<project> Or: - Retry example: sentry issue list 'acme-corp/web' --limit 5 --sort date --period '90d' - Other available projects: acme-corp/api - List projects example: sentry project list 'acme-corp/' ``` ``` $ sentry explore --limit 3 Error: Organization is required. Specify it using: sentry explore <target> Or: - SENTRY_ORG environment variable - sentry cli defaults ``` ### After ``` $ sentry issue list --limit 5 Issues in acme-corp: ╭──────────┬────────────────────────┬────────┬───────┬────────┬───────┬────────╮ │ SHORT ID │ ISSUE │ SEEN │ AGE │ EVENTS │ USERS │ TRIAGE │ ├──────────┼────────────────────────┼────────┼───────┼────────┼───────┼────────┤ │ WEB-1A │ TypeError: Cannot … │ 1h ago │ Nov 1 │ 42 │ 7 │ High │ ├──────────┼────────────────────────┼────────┼───────┼────────┼───────┼────────┤ │ API-7 │ KeyError: 'user_id' │ 1h ago │ Nov 1 │ 42 │ 7 │ High │ ╰──────────┴────────────────────────┴────────┴───────┴────────┴───────┴────────╯ Showing 2 issues ``` ``` $ sentry explore --limit 3 Querying errors in acme-corp: ╭────────────────────────────────────────────────┬─────────╮ │ TITLE │ COUNT() │ ├────────────────────────────────────────────────┼─────────┤ │ TypeError: Cannot read properties of undefined │ 1,204 │ │ KeyError: 'user_id' │ 311 │ ╰────────────────────────────────────────────────┴─────────╯ Showing 2 results. ``` I captured this output against a local mock server with one org and two projects. ### Testing - New tests in `test/lib/context-recovery.test.ts` cover org-wide `issue list`, an org-only command, and the multi-org case that still errors. The first two fail without this change. - `pnpm run tsc` and `pnpm run lint` pass. In the full CLI unit run, the only failures are 11 that also fail on `main` in my sandbox. They are permission and environment checks in completions, db/resilient, code-scanner, errors, file-changes, oauth, auto-login-host-guard, and upgrade. <!-- junior-request-attribution:start --> via **bete**. <!-- 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 <miguel.betegon@sentry.io>
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.
Org auth tokens (
sntrys_…) carry their organization. Legacy sentry-cli used it when--org/SENTRY_ORGwas missing (Config::get_org), but the new CLI ignores it.@sentry/bundler-plugins11.x drivessourcemap upload/release createthroughcreateSentrySDK({ token, org, project }), andorgis often unset because it was never needed with an org token. Those builds now fail.This is the largest event source in CLI-3B: in the last 7 days, 1,642 of 3,733 events (44%) came from library mode (
command:sourcemap.upload/release.create, no user, CLI 0.45.0). 79% of those passed a project but no org.resolveFromEnvVars()now falls back to the token'sorgclaim right afterSENTRY_ORG. An explicit--org/SENTRY_ORGstill wins. A token can only reach its own org, so no other org could have worked.Before
After (token for
acme-corp, local mock server)Separate from this fix: about 20% of the library-mode events carry
--release undefined(the literal string). That comes from the bundler plugin side, not the CLI.Unit test note: 11 tests in 8 files (completions, oauth, upgrade, errors, …) fail in my sandbox both on clean
mainand on this branch. They depend on filesystem permissions and the environment. Everything else passes, andpnpm run tscandpnpm run lintare clean.via bete.
--
View Session [Sentry]