minor cleanup of error-generator.ts

This commit is contained in:
nai-degen 2024-03-18 15:18:18 -05:00
parent 7c64d9209e
commit 7705ee58a0
1 changed files with 15 additions and 8 deletions

View File

@ -31,17 +31,24 @@ function getMessageContent({
}
```
*/
const note = obj?.proxy_note || obj?.error?.message || "";
const header = `**${title}**`;
const friendlyMessage = note ? `${message}\n\n***\n\n*${note}*` : message;
const details = JSON.parse(JSON.stringify(obj ?? {}));
let stack = "";
if (details.stack) {
stack = `\n\nInclude this trace when reporting an issue.\n\`\`\`\n${details.stack}\n\`\`\``;
delete details.stack;
const serializedObj = obj ? "```" + JSON.stringify(obj, null, 2) + "```" : "";
const { stack } = JSON.parse(JSON.stringify(obj ?? {}));
let prettyTrace = "";
if (stack && obj) {
prettyTrace = [
"Include this trace when reporting an issue.",
"```",
stack,
"```",
].join("\n");
delete obj.stack;
}
return `\n\n**${title}**\n${friendlyMessage}${
obj ? `\n\`\`\`\n${JSON.stringify(obj, null, 2)}\n\`\`\`\n${stack}` : ""
}`;
return [header, friendlyMessage, serializedObj, prettyTrace].join("\n\n");
}
type ErrorGeneratorOptions = {