diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-04-16 16:12:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-16 16:12:26 +0200 |
commit | a87be28a46b67e53354f8ce69386057ddbb0f46c (patch) | |
tree | 5615afd3ac57821edd7c782cfe33d253777a8aa3 /core/error.rs | |
parent | 0bb96cde726127291dccb62145e76a50b2efcd2f (diff) |
feat: Better formatting for AggregateError (#14285)
This commit adds "aggregated" field to "deno_core::JsError" that stores
instances of "JsError" recursively to properly handle "AggregateError"
formatting. Appropriate logics was added to "PrettyJsError" and
"console" API to format AggregateErrors.
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'core/error.rs')
-rw-r--r-- | core/error.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/error.rs b/core/error.rs index 59fe170c8..8014dceab 100644 --- a/core/error.rs +++ b/core/error.rs @@ -104,6 +104,7 @@ pub struct JsError { pub frames: Vec<JsStackFrame>, pub source_line: Option<String>, pub source_line_frame_index: Option<usize>, + pub aggregated: Option<Vec<JsError>>, } #[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize)] @@ -305,6 +306,25 @@ impl JsError { } } + // Read an array of stored errors, this is only defined for `AggregateError` + let aggregated_errors = get_property(scope, exception, "errors"); + let aggregated_errors: Option<v8::Local<v8::Array>> = + aggregated_errors.and_then(|a| a.try_into().ok()); + + let mut aggregated: Option<Vec<JsError>> = None; + + if let Some(errors) = aggregated_errors { + if errors.length() > 0 { + let mut agg = vec![]; + for i in 0..errors.length() { + let error = errors.get_index(scope, i).unwrap(); + let js_error = Self::from_v8_exception(scope, error); + agg.push(js_error); + } + aggregated = Some(agg); + } + } + Self { name: e.name, message: e.message, @@ -314,6 +334,7 @@ impl JsError { source_line_frame_index, frames, stack, + aggregated, } } else { // The exception is not a JS Error object. @@ -328,6 +349,7 @@ impl JsError { source_line_frame_index: None, frames: vec![], stack: None, + aggregated: None, } } } |