Skip to content

fix(cli): Fall back to the only organization in resolveOrg (CLI-3B) - #1958

Merged
BYK merged 1 commit into
mainfrom
fix/cli-3b-resolve-org-sole-org
Nov 4, 2026
Merged

BYK merged 1 commit into
mainfrom
fix/cli-3b-resolve-org-sole-org

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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).

via @betegon.

--

View Session [Sentry]

Move the sole-org fallback from two call sites into the shared
resolveOrg cascade, as step 6 after DSN detection. This mirrors the
sole org/project step in resolveOrgAndProject, and covers every command
that resolves an org through resolveOrg (issue @latest and search,
trace view, event view, org positionals), not just
resolveOrgOnlyTarget and resolveOrgOptionalTarget.

Co-Authored-By: Miguel Betegon <28983162+betegon@users.noreply.github.com>
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 4, 2026 8:05pm UTC

Request Review

@BYK
BYK marked this pull request as ready for review November 4, 2026 22:46
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 4, 2026
@BYK
BYK merged commit 4e95319 into main Nov 4, 2026
28 checks passed
@BYK
BYK deleted the fix/cli-3b-resolve-org-sole-org branch November 4, 2026 23:10

This branch was previously deployed

1 inactive deployment
Preview — df673c95 Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants