mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
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>
This commit is contained in:
parent
0bb96cde72
commit
a87be28a46
10 changed files with 210 additions and 78 deletions
|
@ -9,6 +9,8 @@
|
|||
const colors = window.__bootstrap.colors;
|
||||
const {
|
||||
ArrayBufferIsView,
|
||||
AggregateErrorPrototype,
|
||||
ArrayPrototypeUnshift,
|
||||
isNaN,
|
||||
DataViewPrototype,
|
||||
DatePrototype,
|
||||
|
@ -947,16 +949,50 @@
|
|||
}
|
||||
ArrayPrototypeShift(causes);
|
||||
|
||||
return (MapPrototypeGet(refMap, value) ?? "") + value.stack +
|
||||
ArrayPrototypeJoin(
|
||||
let finalMessage = (MapPrototypeGet(refMap, value) ?? "");
|
||||
|
||||
if (ObjectPrototypeIsPrototypeOf(AggregateErrorPrototype, value)) {
|
||||
const stackLines = StringPrototypeSplit(value.stack, "\n");
|
||||
while (true) {
|
||||
const line = ArrayPrototypeShift(stackLines);
|
||||
if (RegExpPrototypeTest(/\s+at/, line)) {
|
||||
ArrayPrototypeUnshift(stackLines, line);
|
||||
break;
|
||||
}
|
||||
|
||||
finalMessage += line;
|
||||
finalMessage += "\n";
|
||||
}
|
||||
const aggregateMessage = ArrayPrototypeJoin(
|
||||
ArrayPrototypeMap(
|
||||
causes,
|
||||
(cause) =>
|
||||
"\nCaused by " + (MapPrototypeGet(refMap, cause) ?? "") +
|
||||
(cause?.stack ?? cause),
|
||||
value.errors,
|
||||
(error) =>
|
||||
StringPrototypeReplace(
|
||||
inspectArgs([error]),
|
||||
/^(?!\s*$)/gm,
|
||||
StringPrototypeRepeat(" ", 4),
|
||||
),
|
||||
),
|
||||
"",
|
||||
"\n",
|
||||
);
|
||||
finalMessage += aggregateMessage;
|
||||
finalMessage += "\n";
|
||||
finalMessage += ArrayPrototypeJoin(stackLines, "\n");
|
||||
} else {
|
||||
finalMessage += value.stack;
|
||||
}
|
||||
|
||||
finalMessage += ArrayPrototypeJoin(
|
||||
ArrayPrototypeMap(
|
||||
causes,
|
||||
(cause) =>
|
||||
"\nCaused by " + (MapPrototypeGet(refMap, cause) ?? "") +
|
||||
(cause?.stack ?? cause),
|
||||
),
|
||||
"",
|
||||
);
|
||||
|
||||
return finalMessage;
|
||||
}
|
||||
|
||||
function inspectStringObject(value, inspectOptions) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue