| 77 | * bounded line and then exit non-zero (Node's default fatal semantics). |
| 78 | */ |
| 79 | export function installFatalHandlers(deps: FatalHandlerDeps = {}): void { |
| 80 | const target = deps.target ?? process; |
| 81 | const exit = deps.exit ?? ((code: number) => process.exit(code)); |
| 82 | const write = deps.write ?? writeStderr; |
| 83 | |
| 84 | target.on('uncaughtException', (error: unknown) => { |
| 85 | write(`[CodeGraph] Uncaught exception: ${describeFatal(error)}\n`); |
| 86 | exit(1); |
| 87 | }); |
| 88 | |
| 89 | target.on('unhandledRejection', (reason: unknown) => { |
| 90 | write(`[CodeGraph] Unhandled rejection: ${describeFatal(reason)}\n`); |
| 91 | exit(1); |
| 92 | }); |
| 93 | } |