summaryrefslogtreecommitdiff
path: root/cli/fmt_errors.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2021-12-29 19:34:13 +0100
committerGitHub <noreply@github.com>2021-12-29 19:34:13 +0100
commit167982be9e7af35e6c12ef6c40c002200bf5e0c0 (patch)
treeb064a4db5beca73e0235e9fc7b15fc624f3b13ab /cli/fmt_errors.rs
parent42777f25416ca292c56587e6cc4dfe9f50bebd81 (diff)
feat: output `cause` on JS runtime errors (#13209)
Diffstat (limited to 'cli/fmt_errors.rs')
-rw-r--r--cli/fmt_errors.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs
index 6c4a4893a..b4e455026 100644
--- a/cli/fmt_errors.rs
+++ b/cli/fmt_errors.rs
@@ -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,