Created
February 5, 2026 17:00
-
-
Save chalkygames123/17e39e400782add27346087cf53d8d6c to your computer and use it in GitHub Desktop.
Utility to recursively stringify and error object with causes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const stringifyErrorChain = (error: unknown, level = 0) => { | |
| let current: unknown = error; | |
| const lines: string[] = []; | |
| while (current instanceof Error) { | |
| const indent = ' '.repeat(level); | |
| lines.push(`${indent}${current.name}: ${current.message}`); | |
| current = current.cause; | |
| level += 1; | |
| } | |
| return lines.join('\n'); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment