Skip to content

Commit

Permalink
feat: align part of StatsError
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder committed Jul 10, 2024
1 parent 0aaf41e commit 9ec7cf4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/rspack_core/src/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ impl Module for NormalModule {
Ok(r) => r.split_into_parts(),
Err(r) => {
let node_error = r.downcast_ref::<NodeError>();
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)
Expand Down
9 changes: 7 additions & 2 deletions crates/rspack_error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, pub String, pub Option<bool>);
#[error("{reason}\n{backtrace}")]
pub struct NodeError {
pub reason: String,
pub stack: Option<String>,
pub backtrace: String,
pub hide_stack: Option<bool>,
}
16 changes: 14 additions & 2 deletions crates/rspack_napi/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ pub trait NapiResultExt<T> {

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()
}
}

Expand Down

0 comments on commit 9ec7cf4

Please sign in to comment.