From 0d3dfc6a559c5957b3ddd556a3ad02aa700c7e40 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 30 Apr 2026 15:27:08 -0700 Subject: [PATCH] handle write failed due to piping through commands like head --- src/main.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main.zig b/src/main.zig index e864ae4..d8054fb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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).