`sentry` commands skip a `.sentryclirc` above the repository root that the docs and `createSentrySDK` read

Offen
#2,580 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
cli, typescript

Rechercherichtung

The two readers differ: the CLI boot fills a cache in packages/cli/src/lib/dsn/project-root.ts that loadSentryCliRc in packages/cli/src/lib/sentryclirc.ts reuses, while packages/cli/src/lib/sdk-invoke.ts skips that boot. Run the attached reproducer after pnpm run bundle in packages/cli to see both forms' results. Done means both forms read the same .sentryclirc files in every step, with the reproducer exiting 0; the maintainers still have to decide whether the code or the docs change.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Environment
  • sentry bundled from main at e72bcc06cafabd9bac550b7aa3b59861e6d0a0f5 with no uncommitted changes (sentry --version: 0.52.0-dev.0), and [email protected] from npm, which does the same
  • node v26.12.1 on win32 x64, and node v20.20.2 on linux x64 with [email protected], which does the same
Steps to Reproduce
  1. Make a home folder whose ~/.sentryclirc sets the org:
    [defaults]
    org=home-org
    
  2. Make a folder org/ whose .sentryclirc sets another org, and a repository below it, org/repo/, holding a .git folder:
    [defaults]
    org=above-org
    
  3. In org/repo/, run sentry release view 1.0.0 with SENTRY_URL and SENTRY_AUTH_TOKEN set (here SENTRY_URL names a local stand-in for the Sentry API), then call createSentrySDK({ url, token }).release.view({ orgVersion: "1.0.0" }) with url naming the same server.
  4. Do steps 2 and 3 again with a folder url/ whose .sentryclirc sets a self-hosted server, above url/repo/.git/:
    [defaults]
    url=https://sentry.example.com
    
  5. Do step 3 again in none/repo/, a repository with no .sentryclirc above it.
Expected Result

sentry commands read the .sentryclirc files the docs describe: "The CLI looks for .sentryclirc files by walking up from your current directory toward the filesystem root" (configuration.md#L9), the walk loadSentryCliRc documents (sentryclirc.ts#L316-L321) and createSentrySDK calls make. So from one folder both forms read the same files: in step 3 both name above-org, in step 4 both reach the server or both are refused, and in step 5 both take home-org from ~/.sentryclirc.

Actual Result

In step 3 the CLI takes the org from ~/.sentryclirc and the SDK takes it from org/.sentryclirc, above the repository:

# in <tmp>/org/repo, below a .sentryclirc that sets org
$ SENTRY_URL=http://127.0.0.1:64229 SENTRY_AUTH_TOKEN=example-token sentry release view 1.0.0
[… 17 lines: the release table …]
Detected from .sentryclirc (<tmp>\home\.sentryclirc)
exit 0; requests the stand-in received: GET /api/0/organizations/home-org/ -> 200, GET /api/0/organizations/home-org/releases/1.0.0/ -> 200

# in <tmp>/org/repo, below a .sentryclirc that sets org
> createSentrySDK({ url: "http://127.0.0.1:64229", token: "example-token" }).release.view({ orgVersion: "1.0.0" })
returned release 1.0.0
exit 0; requests the stand-in received: GET /api/0/organizations/above-org/ -> 200, GET /api/0/organizations/above-org/releases/1.0.0/ -> 200

In step 4 the CLI reaches the server, and the SDK is refused by url/.sentryclirc before it sends a request:

# in <tmp>/url/repo, below a .sentryclirc that sets a self-hosted url
$ SENTRY_URL=http://127.0.0.1:64229 SENTRY_AUTH_TOKEN=example-token sentry release view 1.0.0
[… 17 lines: the release table …]
Detected from .sentryclirc (<tmp>\home\.sentryclirc)
exit 0; requests the stand-in received: GET /api/0/organizations/home-org/ -> 200, GET /api/0/organizations/home-org/releases/1.0.0/ -> 200

# in <tmp>/url/repo, below a .sentryclirc that sets a self-hosted url
> createSentrySDK({ url: "http://127.0.0.1:64229", token: "example-token" }).release.view({ orgVersion: "1.0.0" })
Config at <tmp>\url\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:64229).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exitCode 13
exit 13; requests the stand-in received: none

In step 5 both name home-org.

The CLI reads the .sentryclirc files once, at its boot (cli.ts#L892), in the project-root walk (project-context.ts#L29). That walk stops at a repository-root marker, a VCS folder such as .git, a CI file such as .github or .gitlab-ci.yml, or an .editorconfig with root = true (dsn/project-root.ts#L589-L598, the markers at L60-L84 and L257-L307), at a DSN .env (L584-L587) or at the home folder (L610-L613), and caches what it read as loadSentryCliRc's answer for that folder, "a cache hit instead of a second walk" (L540-L557). An SDK call does not run that boot (sdk-invoke.ts#L408-L420), so its loadSentryCliRc misses the cache and walks to the filesystem root, as the docs say (sentryclirc.ts#L296-L344).

Reproducer

https://gist.github.com/YevheniiKotyrlo/28abb2a95412cd1133f7ec48e0a4401d

It runs steps 1 to 5 in a temporary folder against a local stand-in for the Sentry API that records each request. Each run starts from the caller's environment without its SENTRY_* and GIT_* variables and sets its own: HOME and USERPROFILE (the home folder of step 1), SENTRY_CONFIG_DIR (a folder of its own), TMPDIR, TEMP and TMP (a folder below the temporary folder), SENTRY_URL and SENTRY_AUTH_TOKEN for the CLI (the SDK gets url and token), and SENTRY_CLI_NO_TELEMETRY, SENTRY_CLI_NO_UPDATE_CHECK and NO_COLOR. The verdict depends on the home folder, on SENTRY_CONFIG_DIR, which keeps out a stored login that would let a self-hosted URL pass, and on SENTRY_URL and SENTRY_AUTH_TOKEN (url and token for the SDK), which send both forms to the stand-in; the rest keep telemetry, the update check, colour and what the runs leave in a temporary folder out of it. It exits 1 while the two forms read different files from org/repo or url/repo, 0 once they read the same files from both, the ones the docs describe or, should the docs change instead, the ones the CLI reads now, and 2 when a step fails, a run of step 5 does not name home-org, a run ends another way, or the run is interrupted. A .sentryclirc that sets org or url in a folder above the temporary folder would apply to the SDK's runs from every repository, so the reproducer then stops with 2; point TMPDIR (TEMP and TMP on Windows) at a folder with none above it. It needs Node 20+, and no Sentry account.

node repro.mjs              # sentry@latest from npm
node repro.mjs 0.50.0       # a given version from npm
node repro.mjs <toolkit>    # a getsentry/toolkit checkout: runs `pnpm run bundle` in packages/cli first

Its result on main:

RESULT (exit 1): defect shows (sentry 0.52.0-dev.0 built from e72bcc06cafa): from one folder in a repository, the CLI and the SDK read different .sentryclirc files: below a .sentryclirc that sets org, the CLI named home-org and the SDK named above-org; below a .sentryclirc that sets a self-hosted url, the CLI reached the stand-in and the SDK was refused (exit 13)
Its whole output on main
node v26.12.1 on win32 x64

$ # sentry: getsentry/toolkit at e72bcc06cafabd9bac550b7aa3b59861e6d0a0f5, no uncommitted changes
$ pnpm run bundle   # in packages/cli

$ # the folders, below the temporary folder <tmp>
<tmp>/home/.sentryclirc   [defaults] org=home-org   (HOME and USERPROFILE)
<tmp>/none/repo/.git/
<tmp>/org/.sentryclirc    [defaults] org=above-org
<tmp>/org/repo/.git/
<tmp>/url/.sentryclirc    [defaults] url=https://sentry.example.com
<tmp>/url/repo/.git/

$ sentry --version
0.52.0-dev.0

# in <tmp>/none/repo, below no .sentryclirc
$ SENTRY_URL=http://127.0.0.1:64229 SENTRY_AUTH_TOKEN=example-token sentry release view 1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯

Detected from .sentryclirc (<tmp>\home\.sentryclirc)
exit 0; requests the stand-in received: GET /api/0/organizations/home-org/ -> 200, GET /api/0/organizations/home-org/releases/1.0.0/ -> 200

# in <tmp>/none/repo, below no .sentryclirc
> createSentrySDK({ url: "http://127.0.0.1:64229", token: "example-token" }).release.view({ orgVersion: "1.0.0" })
returned release 1.0.0
exit 0; requests the stand-in received: GET /api/0/organizations/home-org/ -> 200, GET /api/0/organizations/home-org/releases/1.0.0/ -> 200

# in <tmp>/org/repo, below a .sentryclirc that sets org
$ SENTRY_URL=http://127.0.0.1:64229 SENTRY_AUTH_TOKEN=example-token sentry release view 1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯

Detected from .sentryclirc (<tmp>\home\.sentryclirc)
exit 0; requests the stand-in received: GET /api/0/organizations/home-org/ -> 200, GET /api/0/organizations/home-org/releases/1.0.0/ -> 200

# in <tmp>/org/repo, below a .sentryclirc that sets org
> createSentrySDK({ url: "http://127.0.0.1:64229", token: "example-token" }).release.view({ orgVersion: "1.0.0" })
returned release 1.0.0
exit 0; requests the stand-in received: GET /api/0/organizations/above-org/ -> 200, GET /api/0/organizations/above-org/releases/1.0.0/ -> 200

# in <tmp>/url/repo, below a .sentryclirc that sets a self-hosted url
$ SENTRY_URL=http://127.0.0.1:64229 SENTRY_AUTH_TOKEN=example-token sentry release view 1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯

Detected from .sentryclirc (<tmp>\home\.sentryclirc)
exit 0; requests the stand-in received: GET /api/0/organizations/home-org/ -> 200, GET /api/0/organizations/home-org/releases/1.0.0/ -> 200

# in <tmp>/url/repo, below a .sentryclirc that sets a self-hosted url
> createSentrySDK({ url: "http://127.0.0.1:64229", token: "example-token" }).release.view({ orgVersion: "1.0.0" })
Config at <tmp>\url\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:64229).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exitCode 13
exit 13; requests the stand-in received: none

RESULT (exit 1): defect shows (sentry 0.52.0-dev.0 built from e72bcc06cafa): from one folder in a repository, the CLI and the SDK read different .sentryclirc files: below a .sentryclirc that sets org, the CLI named home-org and the SDK named above-org; below a .sentryclirc that sets a self-hosted url, the CLI reached the stand-in and the SDK was refused (exit 13)
Vorherrschende Sprache
TypeScript
Sterne
975
Forks
189
Ø Merge
19 Std. 57 Min.
Gemergte PRs (30 T.)
542

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus getsentry/toolkit

Alle Issues in getsentry/toolkit

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.