pipelines · SEV-4
Pipeline step aborts with exit 2 and no error message
How to confirm it
Reproduce it in isolation
set -eo pipefail COUNT=$(grep -c 'nothing-matches-this' /etc/hosts) echo "never printed: $COUNT"grep exits 1 when it matches nothing. Under set -e inside a command substitution, that kills the script before the echo.
Find every unguarded grep
rg -n '\$\(.*grep' --glob '*.sh' | grep -v '|| true' | head -20Any command substitution containing grep without a guard is the same bug waiting for an input that matches nothing.
The fix
COUNT=$(grep -c 'pattern' file || true) # or, when zero matches is meaningful: if grep -q 'pattern' file; then ...; fiA search finding nothing is not an error. Say so explicitly rather than letting the shell decide.
See where it died
bash -x script.sh 2>&1 | tail -20Trace mode prints the last command executed before the abort, which is the one the exit code came from.
Read the source
Cause
Under `set -e` with `pipefail`, a `grep` inside a command substitution that matches nothing returns non-zero and kills the whole step.
Fix
Guard best-effort blocks with `|| true` and check explicitly. The bug is that a search finding nothing is not an error.
Part of this work
CI Quality Gate at Scale ↗
A parallel, advisory-first quality gate fronting a 200+ repository estate.
The same shape, at scale
Cloudflare — 27 minutes ↗
A WAF rule with catastrophic backtracking pinned CPU to 100% across the entire edge network. It passed tests, because the tests measured correctness, not cost.
Next incident
Spot VM reclamation taking workloads down during cost optimisation ↗