mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-27 19:52:49 +00:00
* fix(cli): exit quietly when stdout's reader is gone When the program that launched the CLI closed its end of stdout, the output write failed with EPIPE and nothing handled the error. Node printed an unhandled 'error' event and exited 1, and the desktop app's CLI passthrough could raise Electron's main-process error dialog. runCli now exits with code 0 on EPIPE from stdout. Other stdout errors still surface as before. Closes #5982 * fix(cli): keep running when stdout's reader is gone Exiting on EPIPE ended a command's own lifecycle: `paseo daemon run` writes its ready line and then supervises the daemon child, so exiting there left the child running without its parent. Drop output nobody reads instead, and let every command finish with its own exit code. * fix(cli): stop following when stdout's reader is gone With EPIPE ignored, `paseo agent logs --follow` and `paseo agent attach` kept running after the program reading their output closed it, until interrupted. Both now wait through one helper that stops on SIGINT, SIGTERM, or EPIPE on stdout, so a closed reader stops them at their next line of output the same way Ctrl+C does. --------- Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
25 lines
845 B
TypeScript
25 lines
845 B
TypeScript
// Commands that stream until stopped (`paseo agent logs --follow`, `paseo agent
|
|
// attach`) stop on Ctrl+C, a termination signal, or when the program reading
|
|
// their output closes its end, as `| head` does. A closed reader shows up as
|
|
// EPIPE on the next write to stdout, so the command stops at its next line of
|
|
// output.
|
|
export function waitForStop(): Promise<void> {
|
|
return new Promise((resolve) => {
|
|
const stop = () => {
|
|
process.off("SIGINT", stop);
|
|
process.off("SIGTERM", stop);
|
|
process.stdout.off("error", stopOnClosedStdout);
|
|
resolve();
|
|
};
|
|
const stopOnClosedStdout = (error: NodeJS.ErrnoException) => {
|
|
if (error.code === "EPIPE") {
|
|
stop();
|
|
}
|
|
};
|
|
|
|
process.on("SIGINT", stop);
|
|
process.on("SIGTERM", stop);
|
|
process.stdout.on("error", stopOnClosedStdout);
|
|
});
|
|
}
|