Skip to content

fix(cli): List the only organization when no project is detected (CLI-3B) - #1947

Merged
betegon merged 1 commit into
mainfrom
fix/cli-3b-list-only-org
Nov 4, 2026
Merged

betegon merged 1 commit into
mainfrom
fix/cli-3b-list-only-org

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

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.

via bete.

--

View Session [Sentry]

…-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>
@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 4:24pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 4, 2026
@betegon
betegon self-requested a review November 4, 2026 16:29
@betegon
betegon merged commit 87b02cb into main Nov 4, 2026
27 checks passed
@betegon
betegon deleted the fix/cli-3b-list-only-org branch November 4, 2026 19:55
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>

This branch was previously deployed

1 inactive deployment
Preview — f910b0c2 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.

1 participant