Repository navigation
fix(cli): a closed reader never panics a command - #190
Draft
medazizktata25 wants to merge 5 commits into
Draft
medazizktata25 wants to merge 5 commits into
medazizktata25 wants to merge 5 commits into
Conversation
medazizktata25
had a problem deploying
to
pr-validation
October 9, 2026 14:16 — with
GitHub Actions
Error
medazizktata25
had a problem deploying
to
pr-validation
October 9, 2026 14:16 — with
GitHub Actions
Error
medazizktata25
had a problem deploying
to
pr-validation
October 9, 2026 14:16 — with
GitHub Actions
Error
medazizktata25
marked this pull request as draft
October 9, 2026 14:18
Contributor
Author
medazizktata25
had a problem deploying
to
pr-validation
October 16, 2026 16:29 — with
GitHub Actions
Error
medazizktata25
had a problem deploying
to
pr-validation
October 16, 2026 16:29 — with
GitHub Actions
Error
medazizktata25
had a problem deploying
to
pr-validation
October 16, 2026 16:29 — with
GitHub Actions
Error
std::env::args() panics on an argument that is not UTF-8, so gfs exited 101 -- the code of any crash -- with the undecodable bytes echoed in the panic message. Read args_os instead and turn the first bad argument into a clap usage error: exit 3 like any value that will not parse, the position named, the bytes never repeated. --json still gets its error object. argv[0] is converted lossily rather than refused, since it is the launch path and not something the user typed.
Every bare println! panicked on BrokenPipe, so `gfs status | head -1` exited 101 -- the code of a crash -- and `gfs schema diff | head` turned "breaking changes" (2) into the same 101. All 335 now go through println_safe!, which records the closed reader and leaves the exit status to the command. Nine printing helpers returned () and now return Result, so a write error other than a closed pipe propagates instead of panicking; every caller was found by compiling with unused_must_use denied. The one deliberate discard is main's --json error object, written just before the process exits with that error's own code. println_safe!() gains an empty arm for the 54 bare newlines.
Main added three bare println! calls for the full-copy snapshot warning; on a closed reader they panicked into 101 like the ones this branch already converted.
clap's help and version output was printed with `e.print().expect(..)`, so a reader that had gone away turned them into a panic and exit 101: gfs --help | head -1 -> PIPESTATUS 101 0 (sleep 1; gfs --version) | true -> PIPESTATUS 101 0 with "panicked at crates/applications/cli/src/lib.rs:847 ... BrokenPipe" on stderr. They are printed before any command runs, so println_safe! never saw them. BrokenPipe is now treated the way println_safe! treats it: output stops, the exit status (0) stands. Any other write error is returned rather than panicking. --help and --version join the closed-reader verdict table.
medazizktata25
force-pushed
the
fix/closed-reader-never-panics-a-command
branch
from
October 26, 2026 14:00
f19a755 to
f20ba9f
Compare
medazizktata25
had a problem deploying
to
pr-validation
October 26, 2026 14:00 — with
GitHub Actions
Error
medazizktata25
had a problem deploying
to
pr-validation
October 26, 2026 14:00 — with
GitHub Actions
Error
medazizktata25
had a problem deploying
to
pr-validation
October 26, 2026 14:00 — with
GitHub Actions
Error
…ntln_safe! A bare println! landed on main after this branch's sweep (1b26050, the reserved 'detached' branch name guard), so 'gfs branch -d detached' on a repository that already carries such a branch still panicked into exit 101 on a closed reader. delete_branch already returns Result, so the call takes a ?.
medazizktata25
requested a deployment
to
pr-validation
October 26, 2026 14:18 — with
GitHub Actions
Waiting
medazizktata25
requested a deployment
to
pr-validation
October 26, 2026 14:18 — with
GitHub Actions
Waiting
medazizktata25
requested a deployment
to
pr-validation
October 26, 2026 14:18 — with
GitHub Actions
Waiting
Contributor
Author
|
Update 2026-10-26: rebased after #179 merged, plus one new commit
|
This branch is waiting to be deployed
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.
Stacked on #189. #179 is merged, so this branch is #189's commit plus four of its own:
a72a9d9(theprintln!sweep),391c85a(status's copy-on-write notice),f20ba9f(--helpand--version) and9de7298(branch -d's detached-workspace notice). When #189 merges, this needs one more rebase.println_safe!landed in #179.The defect
Every bare
println!panics when stdout's reader has gone away (failed printing to stdout: Broken pipe). The process then exits 101, the exit code of a crash. Sogfs status | head -1"crashed".Worse,
gfs schema diff ... | headturned its own verdict, 2 for breaking changes, into that same 101.Measured on a sqlite repository, with the read end closed before gfs writes, 10 runs per command: 10 commands exited 101 on every run.
versionprovidersandproviders sqlitestatusandstatus --jsonbranchandbranch --jsonschema extractschema diffproxy statusThe fix
All
println!calls in the CLI crate now go throughprintln_safe!(338 when this was written, 339 after the latercmd_branch.rsaddition):mainsince and are converted in the follow-up commits, plus one more incmd_branch.rsthatmaingained later (9de7298).println_safe!records the closed reader and leaves the exit code to the command.Helpers that returned nothing: nine printing helpers returned
(), so?could not propagate from them. They now returnResult, so a write error other than a closed pipe (EIO, a full disk) is reported as an error instead of panicking.How the callers were found: by compiling with
-D unused_must_use, which makes every caller that ignored the newResulta hard error. All 14 now propagate with?.The one deliberate discard: the
--jsonerror object inmain.rs, written just before the process exits with that error's own code.println_safe!(): gains an empty arm for the 54 bare newlines.No tokens lost: a check confirmed every rewritten file is token-identical to the original apart from whitespace, the macro name and the added
?. The check itself catches a deleted argument.--helpand--version: clap printed these withe.print().expect(..), before any command runs, sogfs --help | head -1exited 101.f20ba9ftreatsBrokenPipethere the wayprintln_safe!does.Verification
log,log --json,config user.name,fsckandfsck --json. A non-zero verdict is included (schema diff= 2).schema diffstill exits 2 with its reader closed./bin/echofails 15 of 15 rather than passing.a_closed_reader_keeps_the_verdict_of_every_commandintests/json_output.rsruns 7 non-fsck commands on a sqlite repository, so it needs no container runtime. It was checked against two deliberate breaks:println!restored ingfs branch→ the test fails with 101;exit(0)on a broken pipe,main's old behavior →schema diffgets 0 instead of 2.gfs-clisuite, Docker suites included (on colima): 108 passed across 25 test binaries. Two fail:postgres_checkout_lifecycleandclone_range_and_temporal_hydration_elide, both failing identically onmainat e51fc61:postgres_checkout_lifecyclerefuses on the system catalogbase/5/1249, documented as left failing in 5683650;clone_range_and_temporal_hydration_elidereportst0=0 t1=0.cargo fmtandcargo clippy --all-targets -D warningsare clean forgfs-cli, also with-D unused_must_use.Not verified
print!calls (5): not converted; this change coversprintln!only.cmd_configand write no newline, so their failing flush happens at exit and is ignored;configalready survived the harness.cmd_query.rs:91, prints a query's output and probably panics on a closed reader too. Not reproduced.query,compute,user,clone,importandexport. They go through the same macro, but no test proves it.After the rebase
cargo test --workspace --no-fail-faston the rebased branch:json_outputpasses (26/26). The 18 failures are the Docker-backed e2e suites, which could not run (no Docker daemon on the test machine);mainatb10dc37fails the same 18 there. The closed-pipe harness and the Docker suites above were last run before the rebase and were not re-run.cargo clippy -D warningsfails on 54must_useerrors ingfs-domainboth with and without this branch's changes (55 total either way), so it could not be used as a gate here.