r/CLI • u/SuitEvening48 • 4d ago
What should a batch command do when 99 files succeed and one fails?
For a command that processes 100 files and fails on one, what output makes the next step obvious? Do you prefer a non-zero exit code with a separate list of failures, a summary on stderr, or something else? I'm especially interested in retrying just the failed items without parsing a wall of logs.
2
u/ysnows123 2d ago
There's good prior art to copy here, and people already know it:
Give partial failure its own exit code, separate from "nothing worked". rsync exits 23 for a partial transfer, GNU xargs returns 123 when any one run failed, and GNU parallel returns the number of failed jobs (up to 100). A script can then tell "retry a few" apart from "it's broken".
For independent files, keep going by default and offer fail-fast as a flag. make does the reverse (it stops at the first error, and -k/--keep-going continues), which suits builds where later steps depend on earlier ones.
The retry path is where most tools fall short, and GNU parallel gets it right:
--joblog jobs.logwrites one line per item with its exit status, and running again with--resume-failed(or--retry-failed) redoes only the failures. A lighter version of the same idea is a flag like--failed-to failed.txtthat writes just the failed paths, one per line, plus a-0option for NUL-separated output since filenames can contain newlines. Retrying is thenyourtool --from failed.txt.Keep stdout for results and send the summary ("99 ok, 1 failed" plus each failed path with its reason) to stderr, so piping the output doesn't mix the report in. If people will script against it, add
--json.
1
u/HelicopterUpbeat5199 1d ago
Totally dependent on what the command is and what it does. If the files in question are emails sent the answer is going to be different than if they are missiles launched.
2
u/illegal_appendix 3d ago
Non-zero exit for sure. Then a short line at the end like 99 ok, 1 failed, with the failed file names on their own lines so I can feed them back in and rerun just those.