Unverified Commit 6c47eaa2 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Add cause to turbopack-node error (#70456)

Occurs for example in
```
Failed to load chunk server/chunks/08b5e__pnpm_560cbe._.js
	....
Caused by SyntaxError: Identifier 'require' has already been declared
	....
```
parent 039f5809
...@@ -7,6 +7,7 @@ export type StructuredError = { ...@@ -7,6 +7,7 @@ export type StructuredError = {
name: string; name: string;
message: string; message: string;
stack: StackFrame[]; stack: StackFrame[];
cause: StructuredError | undefined
}; };
export function structuredError(e: Error): StructuredError { export function structuredError(e: Error): StructuredError {
...@@ -16,6 +17,7 @@ export function structuredError(e: Error): StructuredError { ...@@ -16,6 +17,7 @@ export function structuredError(e: Error): StructuredError {
name: e.name, name: e.name,
message: e.message, message: e.message,
stack: typeof e.stack === "string" ? parseStackTrace(e.stack!) : [], stack: typeof e.stack === "string" ? parseStackTrace(e.stack!) : [],
cause: e.cause ? structuredError(getProperError(e.cause)) : undefined,
}; };
} }
......
...@@ -267,6 +267,7 @@ pub struct StructuredError { ...@@ -267,6 +267,7 @@ pub struct StructuredError {
pub message: String, pub message: String,
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
stack: Vec<StackFrame<'static>>, stack: Vec<StackFrame<'static>>,
cause: Option<Box<StructuredError>>,
} }
impl StructuredError { impl StructuredError {
...@@ -305,6 +306,20 @@ impl StructuredError { ...@@ -305,6 +306,20 @@ impl StructuredError {
formatting_mode, 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) Ok(message)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment