From 24a92d5a0b64bdf4ce59c986c96c395803dc53f4 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com> Date: Wed, 25 Sep 2024 09:54:57 +0200 Subject: [PATCH] Add cause to turbopack-node error --- .../crates/turbopack-node/js/src/ipc/index.ts | 2 ++ .../crates/turbopack-node/src/source_map/mod.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/turbopack/crates/turbopack-node/js/src/ipc/index.ts b/turbopack/crates/turbopack-node/js/src/ipc/index.ts index 0c1820b6790ab..0f1dfdbfde1e7 100644 --- a/turbopack/crates/turbopack-node/js/src/ipc/index.ts +++ b/turbopack/crates/turbopack-node/js/src/ipc/index.ts @@ -7,6 +7,7 @@ export type StructuredError = { name: string; message: string; stack: StackFrame[]; + cause: StructuredError | undefined }; export function structuredError(e: Error): StructuredError { @@ -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, }; } diff --git a/turbopack/crates/turbopack-node/src/source_map/mod.rs b/turbopack/crates/turbopack-node/src/source_map/mod.rs index 122ca62951b86..35025ef863c99 100644 --- a/turbopack/crates/turbopack-node/src/source_map/mod.rs +++ b/turbopack/crates/turbopack-node/src/source_map/mod.rs @@ -267,6 +267,7 @@ pub struct StructuredError { pub message: String, #[turbo_tasks(trace_ignore)] stack: Vec>, + cause: Option>, } impl StructuredError { @@ -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) } }