diff options
Diffstat (limited to 'cli/fmt_errors.rs')
-rw-r--r-- | cli/fmt_errors.rs | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/cli/fmt_errors.rs b/cli/fmt_errors.rs index 3016e0ff4..b29b97ea2 100644 --- a/cli/fmt_errors.rs +++ b/cli/fmt_errors.rs @@ -4,11 +4,8 @@ use crate::colors::cyan; use crate::colors::italic_bold; use crate::colors::red; use crate::colors::yellow; -use deno_core::error::{AnyError, JsError, JsStackFrame}; +use deno_core::error::{JsError, JsStackFrame}; use deno_core::url::Url; -use std::error::Error; -use std::fmt; -use std::ops::Deref; const SOURCE_ABBREV_THRESHOLD: usize = 150; const DATA_URL_ABBREV_THRESHOLD: usize = 150; @@ -181,12 +178,12 @@ fn format_maybe_source_line( format!("\n{}{}\n{}{}", indent, source_line, indent, color_underline) } -fn format_js_error(js_error: &JsError, is_child: bool) -> String { +fn format_js_error_inner(js_error: &JsError, is_child: bool) -> String { let mut s = String::new(); s.push_str(&js_error.exception_message); if let Some(aggregated) = &js_error.aggregated { for aggregated_error in aggregated { - let error_string = format_js_error(aggregated_error, true); + let error_string = format_js_error_inner(aggregated_error, true); for line in error_string.trim_start_matches("Uncaught ").lines() { s.push_str(&format!("\n {}", line)); } @@ -209,7 +206,7 @@ fn format_js_error(js_error: &JsError, is_child: bool) -> String { s.push_str(&format!("\n at {}", format_frame(frame))); } if let Some(cause) = &js_error.cause { - let error_string = format_js_error(cause, true); + let error_string = format_js_error_inner(cause, true); s.push_str(&format!( "\nCaused by: {}", error_string.trim_start_matches("Uncaught ") @@ -218,33 +215,10 @@ fn format_js_error(js_error: &JsError, is_child: bool) -> String { s } -/// Wrapper around deno_core::JsError which provides colorful -/// string representation. -#[derive(Debug)] -pub struct PrettyJsError(JsError); - -impl PrettyJsError { - pub fn create(js_error: JsError) -> AnyError { - let pretty_js_error = Self(js_error); - pretty_js_error.into() - } -} - -impl Deref for PrettyJsError { - type Target = JsError; - fn deref(&self) -> &Self::Target { - &self.0 - } +pub fn format_js_error(js_error: &JsError) -> String { + format_js_error_inner(js_error, false) } -impl fmt::Display for PrettyJsError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", &format_js_error(&self.0, false)) - } -} - -impl Error for PrettyJsError {} - #[cfg(test)] mod tests { use super::*; |