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

Add cause to turbopack-node error #70456

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions turbopack/crates/turbopack-node/js/src/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type StructuredError = {
name: string;
message: string;
stack: StackFrame[];
cause: StructuredError | undefined
};

export function structuredError(e: Error): StructuredError {
Expand All @@ -16,6 +17,7 @@ export function structuredError(e: Error): StructuredError {
name: e.name,
message: e.message,
stack: typeof e.stack === "string" ? parseStackTrace(e.stack!) : [],
cause: e.cause ? structuredError(getProperError(e.cause)) : undefined,
};
}

Expand Down
15 changes: 15 additions & 0 deletions turbopack/crates/turbopack-node/src/source_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ pub struct StructuredError {
pub message: String,
#[turbo_tasks(trace_ignore)]
stack: Vec<StackFrame<'static>>,
cause: Option<Box<StructuredError>>,
}

impl StructuredError {
Expand Down Expand Up @@ -305,6 +306,20 @@ impl StructuredError {
formatting_mode,
)?;
}

if let Some(cause) = &self.cause {
message.write_str("\nCaused by: ")?;
message.write_str(
&Box::pin(cause.print(
assets_for_source_mapping,
root,
project_dir,
formatting_mode,
))
.await?,
)?;
}

Ok(message)
}
}
Expand Down
Loading