(error: unknown)
| 12 | * 6. `"unknown error"` for null / undefined |
| 13 | */ |
| 14 | export function normalizeErrorMessage(error: unknown): string { |
| 15 | if (error instanceof Error) return error.message; |
| 16 | if (typeof error === "string") return error; |
| 17 | if (typeof error === "object" && error !== null) { |
| 18 | const msg = (error as Record<string, unknown>).message; |
| 19 | if (typeof msg === "string") return msg; |
| 20 | try { |
| 21 | return JSON.stringify(error); |
| 22 | } catch { |
| 23 | try { |
| 24 | return `{${Object.keys(error as object).join(", ")}}`; |
| 25 | } catch { |
| 26 | /* truly opaque object */ |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | return String(error ?? "unknown error"); |
| 31 | } |
no outgoing calls
no test coverage detected