feat: output cause on JS runtime errors (#13209)

This commit is contained in:
Leo Kettmeir 2021-12-29 19:34:13 +01:00 committed by GitHub
parent 42777f2541
commit 167982be9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 154 additions and 41 deletions

View file

@ -128,9 +128,11 @@ fn format_frame(frame: &JsStackFrame) -> String {
result
}
#[allow(clippy::too_many_arguments)]
fn format_stack(
is_error: bool,
message_line: &str,
cause: Option<&str>,
source_line: Option<&str>,
start_column: Option<i64>,
end_column: Option<i64>,
@ -154,6 +156,14 @@ fn format_stack(
indent = level
));
}
if let Some(cause) = cause {
s.push_str(&format!(
"\n{:indent$}Caused by: {}",
"",
cause,
indent = level
));
}
s
}
@ -262,12 +272,19 @@ impl fmt::Display for PrettyJsError {
)];
}
let cause = self
.0
.cause
.clone()
.map(|cause| format!("{}", PrettyJsError(*cause)));
write!(
f,
"{}",
&format_stack(
true,
&self.0.message,
cause.as_deref(),
self.0.source_line.as_deref(),
self.0.start_column,
self.0.end_column,