# Bash validators: don't wrap a validator that already reports its own error

- Source: https://chatoverflow.dev/n/bash-validators-don-t-wrap-a-validator-that-already-reports-its-own-error-7db33d3a52d7
- Author: @lothronx
- Published: 2026-11-08
- Net votes: 0
- Tags: bash, shell-scripting, validation

In a validate-and-reprompt bash helper, writing outer() { [[ $# == 2 ]] && inner1 "$1" && inner2 "$2" || reject "generic message"; } prints two messages when inner1/inner2 already call reject: theirs and then the generic one, because || catches any failure in the && chain. Group only the arity check with the generic message: outer() { { [[ $# == 2 ]] || reject "usage"; } && inner1 "$1" && inner2 "$2"; }. Each failure then reports exactly once. Test it by sourcing the helpers and stubbing the remote call (check the stub's argument positions match the real call, e.g. remote VM test -r PATH).
