Skip to content

fix(cli): Strip sources paths inside maps with --strip-prefix - #2584

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
byk/cli-strip-prefix-sources
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
byk/cli-strip-prefix-sources

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

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-prefix and --strip-common-prefix only touch the sources array 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_prefixes and find_common_prefix:

  • --strip-prefix P removes P/ (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.
  • A non-empty sourceRoot is folded into sources before stripping, and then dropped. URLs and sources starting with / keep their value.
  • --strip-common-prefix strips the common directory 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 before sourceRoot is applied. Index maps are flattened first, so one prefix covers every section.
  • Only the uploaded copy changes. The map on disk stays the same.

What v4 did

v4's strip flags only renamed the uploaded files. The only change it made to sources was 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 upload applies 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. The existing file-name stripping stays. With --no-rewrite, sources are uploaded unchanged (sentry-cli rejected the strip flags together with --no-rewrite). For example, --strip-prefix .. turns ../src/index.ts into src/index.ts.

The flag help, the generated skill reference, and the v3 migration guide now describe this.

Open question: should --no-rewrite also strip sources? The change only affects the uploaded copy, so it would leave deployed files alone. It would also let the wizard's Wrangler script (--no-rewrite) use --strip-prefix. sentry-cli had no equivalent because it rejected that combination.

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.

via @BYK.

--

View Session [Sentry]

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>
@sentry-junior
sentry-junior Bot requested a review from BYK November 28, 2026 02:08
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Nov 28, 2026 2:18am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 28, 2026 2:18am UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 28, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

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

function stripPrefix(source: string, prefix: string): string {
const withSlash = prefix.endsWith("/") ? prefix : `${prefix}/`;
return source.startsWith(withSlash) ? source.slice(withSlash.length) : source;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backslash sources fail to strip

Medium Severity

splitPath and isAbsolutePath accept \ so a Windows common prefix like C:\work can be computed, but stripPrefix always appends /. Sources such as C:\work\app\a.ts therefore never start with the computed prefix, and --strip-common-prefix / --strip-prefix do not rewrite them. Inject already turns \ into / when it mutates a map; maps that skip inject (debug IDs already present) keep backslashes and hit this path.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3d5c4cb. Configure here.

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 518525cb Deployed Nov 28, 2026 by vercel[bot]
Preview – sentry-local — 518525cb Deployed Nov 28, 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.

sourcemap upload can't rewrite sources paths inside maps

1 participant