diff options
| author | 2022-04-03 21:28:45 -0700 | |
|---|---|---|
| committer | 2022-04-03 21:28:45 -0700 | |
| commit | be70e08671899f0b11f1b1b7372d832c00188aff (patch) | |
| tree | 4da58c42d8a571ec640125886f36c81a0b7953ce | |
| parent | 480d4b98c759f7eac1ecedeef6604c4d339eb9c9 (diff) | |
| download | bun-be70e08671899f0b11f1b1b7372d832c00188aff.tar.gz bun-be70e08671899f0b11f1b1b7372d832c00188aff.tar.zst bun-be70e08671899f0b11f1b1b7372d832c00188aff.zip | |
[bun error] Handle error messages with missing name/message better
| -rw-r--r-- | packages/bun-error/markdown.ts | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/packages/bun-error/markdown.ts b/packages/bun-error/markdown.ts index 72f36674c..f61996d18 100644 --- a/packages/bun-error/markdown.ts +++ b/packages/bun-error/markdown.ts @@ -45,21 +45,31 @@ export function exceptionsToMarkdown(exceptions: JSExceptionType[]): string { function exceptionToMarkdown(exception: JSException): string { const { name: name_, message: message_, stack } = exception; + var name = String(name_).trim(); var message = String(message_).trim(); + // check both so if it turns out one of them was only whitespace, we don't count it + const hasName = name_ && name_.length > 0 && name.length > 0; + const hasMessage = message_ && message_.length > 0 && message.length > 0; + let markdown = ""; if ( - name === "Error" || - name === "RangeError" || - name === "TypeError" || - name === "ReferenceError" || - name === "DOMException" + (name === "Error" || + name === "RangeError" || + name === "TypeError" || + name === "ReferenceError" || + name === "DOMException") && + hasMessage ) { markdown += `**${message}**\n`; - } else { + } else if (hasName && hasMessage) { markdown += `**${name}**\n${message}\n`; + } else if (hasMessage) { + markdown += `${message}\n`; + } else if (hasName) { + markdown += `**${name}**\n`; } if (stack.frames.length > 0) { |
