(dataDir?: string)
| 51 | } |
| 52 | |
| 53 | export function installProcessErrorLogging(dataDir?: string): void { |
| 54 | if (processHandlersInstalled) return; |
| 55 | processHandlersInstalled = true; |
| 56 | |
| 57 | process.on('uncaughtExceptionMonitor', (error) => { |
| 58 | if (loggedUnhandledRejections.has(error)) return; |
| 59 | writeErrorLog({ |
| 60 | level: 'error', |
| 61 | source: 'process.uncaughtException', |
| 62 | message: error instanceof Error ? error.message : String(error), |
| 63 | error, |
| 64 | }, { dataDir }); |
| 65 | }); |
| 66 | |
| 67 | process.on('unhandledRejection', (reason) => { |
| 68 | const error = reason instanceof Error ? reason : new Error(`Unhandled rejection: ${String(reason)}`); |
| 69 | writeErrorLog({ |
| 70 | level: 'error', |
| 71 | source: 'process.unhandledRejection', |
| 72 | message: error.message, |
| 73 | error, |
| 74 | }, { dataDir }); |
| 75 | loggedUnhandledRejections.add(error); |
| 76 | setImmediate(() => { |
| 77 | throw error; |
| 78 | }); |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | export function formatErrorLogEntry(entry: ErrorLogEntry, now = new Date()): string { |
| 83 | const error = normalizeError(entry.error); |
no test coverage detected