(code: number | null, signal: NodeJS.Signals | null)
| 358 | }; |
| 359 | |
| 360 | const onExit = (code: number | null, signal: NodeJS.Signals | null) => { |
| 361 | if (resolved) { |
| 362 | // Post-boot exit. Expected when we stopped it ourselves (quit, restart, |
| 363 | // update) and when something outside the app interrupted it — the child |
| 364 | // shares Electron's process group, so a group-wide SIGINT reaches it |
| 365 | // directly and surfaces as code 130. Only the rest is a crash under a |
| 366 | // live window, reported upstream with the stderr tail. |
| 367 | const classification = classifySidecarExit({ |
| 368 | code, |
| 369 | signal, |
| 370 | stoppedByUs: expectedExits.has(child), |
| 371 | appQuitting: isAppQuitting(), |
| 372 | }); |
| 373 | if (classification.kind === "managed-stop") { |
| 374 | sidecarLog.info(`exited (code=${code} signal=${signal}) — ${classification.reason}`); |
| 375 | return; |
| 376 | } |
| 377 | if (classification.kind === "external-shutdown") { |
| 378 | // The server really is gone, so the window still has to say so; it |
| 379 | // just wasn't a crash, so nothing is reported. |
| 380 | sidecarLog.info( |
| 381 | `Sidecar shut down by ${classification.reason} (code=${code} signal=${signal})`, |
| 382 | ); |
| 383 | unexpectedExitListener?.({ reported: false }); |
| 384 | return; |
| 385 | } |
| 386 | const message = `Sidecar exited unexpectedly (code=${code} signal=${signal})`; |
| 387 | sidecarLog.error(message); |
| 388 | reportSidecarCrash(message, stderrBuffer); |
| 389 | unexpectedExitListener?.({ reported: true }); |
| 390 | return; |
| 391 | } |
| 392 | if (rejected) return; |
| 393 | // Detect bind failure — the Node listener prints either "EADDRINUSE" or |
| 394 | // "address already in use" on stderr before exiting non-zero. |
| 395 | if (/EADDRINUSE|address already in use/i.test(stderrBuffer)) { |
| 396 | reject(new SidecarPortInUseError(settings.port)); |
| 397 | return; |
| 398 | } |
| 399 | const message = `Sidecar exited before ready (code=${code} signal=${signal}). Stderr:\n${stderrBuffer}`; |
| 400 | // oxlint-disable-next-line executor/no-error-constructor -- boundary: sidecar boot failure surfaces here as a rejected start promise |
| 401 | reject(new Error(message)); |
| 402 | }; |
| 403 | |
| 404 | child.stdout?.on("data", onStdout); |
| 405 | child.stderr?.on("data", onStderr); |
nothing calls this directly
no test coverage detected