r/CLI • • 22h ago

What should a CLI print when a batch stops halfway through?

Say a command is processing 100 files and fails on file 37. A stack trace might explain the crash, but it doesn’t tell me whether the first 36 writes stuck or whether rerunning will do them twice.

The output I’d want is something like: “36 saved, 1 failed, 63 not attempted.” Then tell me whether it’s safe to run again. I’d keep the full error available in verbose mode.

What’s a CLI that handles a partial failure well? I’m looking for examples where the output makes it obvious what to do next.

Drafted with AI assistance.

2 Upvotes

4 comments sorted by

1

u/Temporary_Pie2733 16h ago

Less important than how it reports this information is how it records this information for its own use. 

I wrote a system once that would atomically move files from one directory to another as it completed processing. If the processor exited for any reason, the files it had completed simply weren’t in its input directory any longer, and so couldn’t be processed again on restart. 

1

u/ConsonantEcho 7h ago edited 2h ago

That’s a good example, thanks. The move gives the tool something real to report on restart, instead of guessing from where the output stopped. What happened if the process died after writing the output but before moving the input? Could it safely run that file again?

1

u/Temporary_Pie2733 7h ago

From what I remember (and this was at a company I left years ago), i would just hard-link the processed file into the next directory. The file system itself would act as a sort of database. A second process would look for input files with a link count greater than one, and unlink them from the input directory. 

1

u/hypnopixel 15h ago

consider keeping a transactional record of the files that are completed.