Skip to content

Commit

Permalink
fix: fall back to co-location heuristic if sourcemap url appears to b…
Browse files Browse the repository at this point in the history
…e a remote path

Fixes #1870.
  • Loading branch information
brettdh committed Jul 17, 2024
1 parent 4e4a261 commit 93fddd5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"eslint.autoFixOnSave": true,
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
16 changes: 15 additions & 1 deletion src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ fn is_remote_url(url: &str) -> bool {
};
}

/// Return true if url appears to be a URL path.
/// Most often, a URL path will begin with `/`,
/// particularly in the case of static asset collection and hosting,
/// but such a path is very unlikely to exist in the local filesystem.
fn is_url_path(url: &str) -> bool {
url.starts_with('/') && !Path::new(url).exists()
}

/// Return true iff url is probably not a local file path.
fn is_remote_sourcemap(url: &str) -> bool {
is_remote_url(url) || is_url_path(url)
}

impl SourceMapProcessor {
/// Creates a new sourcemap validator.
pub fn new() -> SourceMapProcessor {
Expand Down Expand Up @@ -378,7 +391,8 @@ impl SourceMapProcessor {
// that can't be resolved to a source map file.
// Instead, we pretend we failed to discover the location, and we fall back to
// guessing the source map location based on the source location.
let location = discover_sourcemaps_location(contents).filter(|loc| !is_remote_url(loc));
let location =
discover_sourcemaps_location(contents).filter(|loc| !is_remote_sourcemap(loc));
let sourcemap_reference = match location {
Some(url) => SourceMapReference::from_url(url.to_string()),
None => match guess_sourcemap_reference(&sourcemaps, &source.url) {
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
$ sentry-cli sourcemaps inject ./server ./static
? success
> Searching ./server
> Found 14 files
> Found 16 files
> Searching ./static
> Found 8 files
> Analyzing 22 sources
> Analyzing 24 sources
> Injecting debug ids

Source Map Debug ID Injection Report
Expand All @@ -14,6 +14,7 @@ Source Map Debug ID Injection Report
[..]-[..]-[..]-[..]-[..] - ./server/chunks/1.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_embedded.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted_full.js
[..]-[..]-[..]-[..]-[..] - ./server/flight-manifest.js
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js
[..]-[..]-[..]-[..]-[..] - ./server/pages/api/hello.js
Expand All @@ -23,6 +24,7 @@ Source Map Debug ID Injection Report
[..]-[..]-[..]-[..]-[..] - ./static/chunks/pages/asdf-05b39167abbe433b.js
Modified: The following sourcemap files have been modified to have debug ids
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js.map
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted_full.js.map
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js.map
[..]-[..]-[..]-[..]-[..] - ./static/chunks/575-bb7d7e0e6de8d623.js.map
Ignored: The following source files already have debug ids
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/_fixtures/inject/server/dummy_hosted.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93fddd5

Please sign in to comment.