handle write failed due to piping through commands like head

This commit is contained in:
Emil Lerch 2026-04-30 15:27:08 -07:00
parent add0222ebc
commit 6293a02c59

View file

@ -161,6 +161,18 @@ fn resolveUserPath(
}
pub fn main() !u8 {
return runCli() catch |err| switch (err) {
// Downstream pipe closed (e.g., `zfin earnings AAPL | head`). Zig's
// file writer surfaces EPIPE as WriteFailed. Treat as a clean exit
// the consumer got what it needed and closed the pipe; further
// output isn't an error from our perspective. Matches `ls | head`,
// `git log | head`, etc.
error.WriteFailed, error.BrokenPipe => 0,
else => err,
};
}
fn runCli() !u8 {
// Long-lived allocator for things that span the whole process. Only
// actually used for the early argsAlloc and the TUI path CLI
// commands run under a per-invocation arena (see below).