handle write failed due to piping through commands like head
All checks were successful
Generic zig build / build (push) Successful in 1m59s
Generic zig build / deploy (push) Successful in 17s

This commit is contained in:
Emil Lerch 2026-04-30 15:27:08 -07:00
parent f436ca5a86
commit 0d3dfc6a55
Signed by: lobo
GPG key ID: A7B62D657EF764F8

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).