A closed pipe on stdout is reported as 'zfj: WriteFailed' and exit 3 #34
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jeff/zfj#34
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When whatever reads zfj's stdout closes the pipe before zfj has finished writing, zfj prints
zfj: WriteFailedto stderr and exits 3, the exit status for a broken environment.It only happens when the output is larger than the pipe's buffer (64 KiB on Linux): smaller output has all been written before
headexits, sozfj issue list | head -1is quiet. That makes it most likely withrun view --log,--paginateandopresponses, but every command writes through the samectx.stdout, so none is exempt.Why
Zig ignores
SIGPIPE, so the write fails withEPIPE,Io.Writerreports that aserror.WriteFailed, and the catch-all insrc/cli/main.zig(run(...) catch |err| ctx.environment("{s}", .{@errorName(err)})) turns it into an environment error.What it should do
A reader going away is not a failure of zfj's, and
cmd | headis ordinary use, so it should end quietly: no message on stderr. Other tools differ on the status —gitdies ofSIGPIPE(141 from the shell),ghexits 0 — and the choice needs making. Exiting 0 keepsset -o pipefailscripts that use| headworking.The writer's underlying error has to be checked rather than
WriteFailedalone, so that a full disk or an I/O error on a redirect to a file is still reported.