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