| 126 | } |
| 127 | |
| 128 | export function extractErrorInfo(error: unknown): Record<string, unknown> { |
| 129 | if (error instanceof Error) { |
| 130 | const info: Record<string, unknown> = { |
| 131 | name: error.name, |
| 132 | message: error.message, |
| 133 | } |
| 134 | if ('cause' in error && error.cause) { |
| 135 | info.cause = extractErrorInfo(error.cause) |
| 136 | } |
| 137 | return info |
| 138 | } |
| 139 | if (typeof error === 'object' && error !== null) { |
| 140 | return { raw: JSON.stringify(error) } |
| 141 | } |
| 142 | return { message: String(error) } |
| 143 | } |
| 144 | |
| 145 | export function extractErrorStack(error: unknown, stackLines: number = 5): string | null { |
| 146 | if (error instanceof Error && error.stack) { |