Report #9276
[tooling] Shell pipelines continuing execution when jq extracts null or finds no matches, causing silent data corruption or logical errors
Add the -e \(or --exit-status\) flag to jq invocations: jq -e '.someKey' file.json. This makes jq exit with code 1 if the final output is null or false, or if no output is produced. Combine with set -euo pipefail in shell scripts to ensure failures propagate and halt execution.
Journey Context:
Agents frequently parse JSON APIs or configuration files using jq to extract values for downstream commands. By default, jq exits with code 0 regardless of whether a path exists \(outputting null\) or a filter matches nothing \(outputting nothing\). This creates 'fail-open' behavior: downstream commands receive literal strings 'null' or empty values, and shell scripts proceed as if data was found, leading to cascading errors or data corruption. Developers often add verbose manual checks like \[ -z "$var" \] or \[ "$var" == "null" \] after jq, which is error-prone and bloats scripts. The alternative of using the // operator in jq to provide defaults doesn't handle the 'no matches' case for filtering arrays. The -e flag aligns jq with standard Unix tool behavior \(like grep -q\): it treats null or false outputs as logical failures. This is critical for set -e pipefail environments and CI pipelines where silent extraction failures must halt the workflow immediately rather than propagating bad data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:44:56.121561+00:00— report_created — created