(value: unknown)
| 38 | * formatting. Pure and total — never throws, never touches `.stack`. |
| 39 | */ |
| 40 | export function describeFatal(value: unknown): string { |
| 41 | if (value instanceof Error) { |
| 42 | const name = typeof value.name === 'string' && value.name ? value.name : 'Error'; |
| 43 | // `message` is a plain own/proto string property — reading it does NOT |
| 44 | // format the stack (which is what can loop forever, #850). |
| 45 | const message = typeof value.message === 'string' ? value.message : ''; |
| 46 | return message ? `${name}: ${message}` : name; |
| 47 | } |
| 48 | try { |
| 49 | return String(value); |
| 50 | } catch { |
| 51 | // e.g. an object with a throwing `toString` / `Symbol.toPrimitive`. |
| 52 | return '<unstringifiable value>'; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** Best-effort synchronous stderr write that can never keep a doomed process alive. */ |
| 57 | function writeStderr(line: string): void { |
no outgoing calls
no test coverage detected