Skip to content

Commit

Permalink
fix(respecDocWriter): stringify uncaught Error objects (#4781)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Nov 26, 2024
1 parent 6ca4e1a commit 149bb4a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/respecDocWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ function handleConsoleMessages(page, onError, onWarning) {
if (typeof obj === "string") {
// Old ReSpec versions might report errors as strings.
return JSON.stringify({ message: String(obj) });
} else if (obj instanceof Error && !obj.plugin) {
return JSON.stringify({
message: obj.message,
plugin: "unknown",
name: obj.name,
stack: obj.stack?.replace(
obj.message,
`${obj.message.slice(0, 30)}…`
),
});
} else {
// Ideally: `obj instanceof RsError` and `RsError instanceof Error`.
return JSON.stringify(obj);
Expand All @@ -335,6 +345,7 @@ function handleConsoleMessages(page, onError, onWarning) {
switch (type) {
case "error":
return onError(JSON.parse(text));
case "warn":
case "warning":
return onWarning(JSON.parse(text));
}
Expand Down

0 comments on commit 149bb4a

Please sign in to comment.