Repository navigation
feat: add checked stdout writer to cli - #77
Merged
Merged
Conversation
cli.put, cli.print, and cli.out ignore write failures, which suits diagnostic output on stderr while leaving callers that capture or evaluate stdout unaware of EBADF or ENOSPC. Front ends that print both multi-line status and captured documents had to maintain their own write wrapper and sticky failure flag. Add cli.Stdout with write, print, and finish methods plus one-shot cli.writeOut. On the first write failure, Stdout sets failed, prints "TOOL: cannot write output (ERRNO)" on err_fd, and returns false; later writes return false without repeating the diagnostic, and finish turns exit status 0 into 1. Tests cover short and heap-formatted writes, sticky EBADF and ENOSPC reporting, exit status conversion, and cli.writeOut on /dev/full.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cli.put,cli.print, andcli.outignore write errors, which suitsprogress messages while leaving callers that capture or evaluate
standard output unaware of
EBADF,EPIPE, orENOSPC. Front endsthat emit both line-by-line output and captured payloads had to keep a
local checked-write helper and failure flag.
Add
cli.Stdout(write,print, andfinish) and one-shotcli.writeOuttozig_common.cli:Stdoutlatchesfailed, printsTOOL: cannot write output (ERRNO)once toerr_fd, and returnsfalse.falsewithout repeating the message, andStdout.finishmaps exit status0to1while preserving nonzerostatuses.
Verification
zig fmtformatting check acrossbuild.zig,build.zig.zon,src, andtests.zig build testunit suite, includingStdoutandwriteOutcasesfor short and heap-allocated writes,
EBADF,/dev/full(ENOSPC),and exit status conversion.
towncrierchangelog draft build.