Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make library code less verbose in stack traces #4706

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions crates/turbopack-node/src/source_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ fn write_resolved(
))
)?;
}
Ok(ResolvedSourceMapping::MappedLibrary {
frame,
project_path,
}) => {
// There is a mapping to a file in the project directory, but to library code
write!(
writable,
"{PADDING}{}",
formatting_mode.lowlight(&format_args!(
"at {} [{}]",
frame.with_path(&project_path.path),
original_frame.with_name(None)
))
)?;
}
Ok(ResolvedSourceMapping::MappedProject {
frame,
project_path,
Expand Down Expand Up @@ -175,6 +190,10 @@ enum ResolvedSourceMapping {
project_path: FileSystemPathReadRef,
lines: FileLinesContentReadRef,
},
MappedLibrary {
frame: StackFrame<'static>,
project_path: FileSystemPathReadRef,
},
}

async fn resolve_source_mapping(
Expand Down Expand Up @@ -212,6 +231,7 @@ async fn resolve_source_mapping(
.await?;
match &*trace {
TraceResult::Found(frame) => {
let lib_code = frame.file.contains("/node_modules/");
if let Some(project_path) = frame.file.strip_prefix(concatcp!(
"/",
SOURCE_MAP_ROOT_NAME,
Expand All @@ -220,12 +240,19 @@ async fn resolve_source_mapping(
"]/"
)) {
let fs_path = project_dir.join(project_path);
let lines = fs_path.read().lines().await?;
return Ok(ResolvedSourceMapping::MappedProject {
frame: frame.clone(),
project_path: fs_path.await?,
lines,
});
if lib_code {
return Ok(ResolvedSourceMapping::MappedLibrary {
frame: frame.clone(),
project_path: fs_path.await?,
});
} else {
let lines = fs_path.read().lines().await?;
return Ok(ResolvedSourceMapping::MappedProject {
frame: frame.clone(),
project_path: fs_path.await?,
lines,
});
}
}
Ok(ResolvedSourceMapping::Mapped {
frame: frame.clone(),
Expand Down