Repository navigation
fix(cli): Strip sources paths inside maps with --strip-prefix - #2584
Conversation
sentry-cli v2 and v3 apply --strip-prefix and --strip-common-prefix to the `sources` paths inside each uploaded source map. v4 only stripped the uploaded file paths, so maps with sources relative to the build output (Wrangler's `../src/index.ts`) kept those paths in stack frames. `sourcemap upload` now strips the uploaded copy of each map the same way, leaving the files on disk unchanged. --no-rewrite uploads sources unchanged. Fixes #2576 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3d5c4cb. Configure here.
…backslashes Three deliberate departures from sentry-cli for the strip flags: - --strip-prefix and --strip-common-prefix also rewrite `sources` with --no-rewrite. Only the uploaded copy changes; sentry-cli rejected the combination. - --strip-common-prefix drops each source's file name before computing the common prefix, so a map with one absolute source gets its directory stripped instead of being left alone. - Backslashes in `sources` become `/` before stripping, as inject already does, so Windows paths like C:\work\app\a.ts can be stripped. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…pping sentry-cli prepended `sourceRoot` to any source not starting with `/`, `http:` or `https:`, so `C:/work/a.ts` became `<root>/C:/work/a.ts` and the strip flags no longer matched it. Drive paths, including the ones backslash normalization now produces, count as absolute.
BYK
left a comment
There was a problem hiding this comment.
Still not matched, and out of scope here: sentry-cli accepted --strip-prefix more than once and allowed it together with --strip-common-prefix. v4 takes one prefix, and the two flags are mutually exclusive.
I think we can and probably should support multiple --strip-prefix flags to allow multiple prefixes to be stripped? Also curious why we make --strip-common-prefix mutually exclusive here? I can see it may get a bit confusing but I can definitely see them working together?
--no-rewrite: the strip flags rewrite sources with --no-rewrite too, in the uploaded copy only, so deployed files are untouched. sentry-cli rejected the strip flags together with --no-rewrite. This lets uploads of already-deployed output, like the wizard's Wrangler script, strip sources.
Is this safe as we seem to be ignoring --no-rewrite in this case?
|
@BYK answers to your three questions:
Filed #2596 as follow-up. |
Wrangler writes map sources relative to the output directory, such as `../src/index.ts`, so stack frames showed that path. The wizard's `sentry:sourcemaps` script now passes `--strip-prefix ..`, which turns them into `src/index.ts` in the uploaded copy. This relies on #2584, which strips `sources` under `--no-rewrite` too.

Fixes #2576. Part of the v2/v3 → v4 parity work in #1965; found while porting the Wrangler source maps flow in #2529.
What sentry-cli did
In sentry-cli (v2 and v3,
sourcemaps upload),--strip-prefixand--strip-common-prefixonly touch thesourcesarray inside each uploaded map. They never change the uploaded file names. The help text says so: "This will not modify the uploaded sources paths."The rules come from rust-sourcemap's
strip_prefixesandfind_common_prefix:--strip-prefix PremovesP/(a/is added if missing) from the start of each source. Sources that don't start with it stay as they are. It's a raw string match, with no path resolution.sourceRootis folded intosourcesbefore stripping, and then dropped. URLs and sources starting with/keep their value.--strip-common-prefixstrips the common prefix of each map's absolute sources. Relative sources don't count, and a bare/prefix is ignored. For a regular map the prefix is computed beforesourceRootis applied. Index maps are flattened first, so one prefix covers every section.What v4 did
v4's strip flags only renamed the uploaded files. The only change it made to
sourceswas turning backslashes into forward slashes. So maps whose sources are relative to the build output, like Wrangler's../src/index.ts, kept those paths in stack frames.What v4 does now
sourcemap uploadapplies the rules above to the uploaded copy of every map: external maps, inline maps, and each section of an index map. The files on disk are left alone, and the existing file-name stripping stays. For example,--strip-prefix ..turns../src/index.tsintosrc/index.ts.Deliberate departures from sentry-cli
--no-rewrite: the strip flags rewritesourceswith--no-rewritetoo, in the uploaded copy only, so deployed files are untouched. sentry-cli rejected the strip flags together with--no-rewrite. This lets uploads of already-deployed output, like the wizard's Wrangler script, stripsources.--strip-common-prefixdrops each source's file name before computing the common prefix, so it always stops at a directory. A map with one absolute source, such as/home/ci/app/src/a.ts, becomesa.ts. In sentry-cli the prefix was the whole path, so that source was left unchanged.sourcesbecome/before stripping, as inject already does when it rewrites a map. Sources likeC:\work\app\a.tscan then be stripped. In sentry-cli the prefix always ends in/, so backslash paths never matched. This matters for maps that inject skips because they already carry a debug ID.sourceRootand Windows drive paths: when a map has asourceRoot, it is not prepended to drive paths such asC:/work/a.ts, which now count as absolute like/…paths. sentry-cli only skipped sources starting with/,http:orhttps:, so it turned them into<sourceRoot>/C:/work/a.tsand the strip no longer matched.The flag help, the generated skill reference, and the v3 migration guide now describe this.
Still not matched, and out of scope here: sentry-cli accepted
--strip-prefixmore than once and allowed it together with--strip-common-prefix. v4 takes one prefix, and the two flags are mutually exclusive.via @BYK.
--
View Session [Sentry]