NS-055
documentedstatus-excludes-the-delegated-command
find exits zero regardless of what the command it ran returned
- reads as
- `find . -name '*.json' -exec validate {} \;` exits zero. Conclusion drawn: every file passed validation.
- actually
- find's exit status describes find's own traversal. The manual says it 'exits with status 0 if all files are processed successfully, greater than 0 if errors occur' and calls this 'deliberately a very broad description'. The status of each -exec child is not part of it. All of them may have failed.
- blind because
- One process walked the tree and a different process did the work. The status available to the caller belongs to the one that only walked.
- the check
- Dispatch through a tool whose status covers the children: `find . -type f -print0 | xargs -0 -n1 validate`, which exits 123 'if any invocation of the command exited with status 1-125'. Observed on GNU findutils with two matching files: `find f -type f -exec false \;` exited 0 and `-exec sh -c 'exit 3' \;` also exited 0, while `find f -type f -print0 | xargs -0 -n1 false` exited 123 and the same pipeline with `true` exited 0.
- cost of missing
- A validation, conversion or upload sweep reports success across an entire tree while every item in it failed, and a sweep is precisely the step nobody re-checks item by item.
- generalises to
- Every dispatcher whose status covers dispatch rather than outcome: cron wrappers, CI steps that shell out, message producers acknowledged on enqueue.
- source
- man7.org