From 9ec7cf4857a2ac2c766e218bffc277f17b18e2a2 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Wed, 10 Jul 2024 14:51:18 +0800 Subject: [PATCH] feat: align part of StatsError --- crates/rspack_core/src/normal_module.rs | 4 ++-- crates/rspack_error/src/error.rs | 9 +++++++-- crates/rspack_napi/src/errors.rs | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index 25202fc86c41..5be073fea195 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -404,8 +404,8 @@ impl Module for NormalModule { Ok(r) => r.split_into_parts(), Err(r) => { let node_error = r.downcast_ref::(); - let stack = node_error.and_then(|e| e.1.clone()); - let hide_stack = node_error.and_then(|e| e.3); + let stack = node_error.and_then(|e| e.stack.clone()); + let hide_stack = node_error.and_then(|e| e.hide_stack); let e = ModuleBuildError(r).boxed(); let d = Diagnostic::from(e) .with_stack(stack) diff --git a/crates/rspack_error/src/error.rs b/crates/rspack_error/src/error.rs index 1ef862eaa394..5d2c917dddb3 100644 --- a/crates/rspack_error/src/error.rs +++ b/crates/rspack_error/src/error.rs @@ -368,5 +368,10 @@ fn _assert() { /// (message, stack, backtrace, hide_stack) #[derive(Debug, Error, Diagnostic)] #[diagnostic()] -#[error("{0}\n{2}")] -pub struct NodeError(pub String, pub Option, pub String, pub Option); +#[error("{reason}\n{backtrace}")] +pub struct NodeError { + pub reason: String, + pub stack: Option, + pub backtrace: String, + pub hide_stack: Option, +} diff --git a/crates/rspack_napi/src/errors.rs b/crates/rspack_napi/src/errors.rs index 2e917ee7af46..98006e0f0788 100644 --- a/crates/rspack_napi/src/errors.rs +++ b/crates/rspack_napi/src/errors.rs @@ -15,12 +15,24 @@ pub trait NapiResultExt { impl NapiErrorExt for Error { fn into_rspack_error(self) -> rspack_error::Error { - NodeError(self.reason, None, "".to_string(), None).into() + (NodeError { + reason: self.reason, + stack: None, + backtrace: "".to_string(), + hide_stack: None, + }) + .into() } fn into_rspack_error_with_detail(self, env: &Env) -> rspack_error::Error { let (reason, stack, backtrace, hide_stack) = extract_stack_or_message_from_napi_error(env, self); - NodeError(reason, stack, backtrace.unwrap_or_default(), hide_stack).into() + (NodeError { + reason, + stack, + backtrace: backtrace.unwrap_or_default(), + hide_stack, + }) + .into() } }