FEATURE: Conditional and Error Control
| Field | Value |
|---|---|
| Version | 20261028 V1 |
| Description | Evaluate jq conditionals, alternatives, and error handlers. |
| Depends On | FEATURE-Operators.md |
| Provides | jq conditional and error control |
| Consumes | jq operators |
Behavior
For each condition output, evaluate the corresponding branch against the condition's input; only false and null select the false branch. An omitted else branch is identity. Support elif and conditions that yield zero or multiple values.
The alternative operator emits all non-false, non-null outputs of its left side, or evaluates its right side when none exist. Try and catch handle errors raised within their expression boundaries, passing the error value to the handler. The optional suffix suppresses errors as an empty handler. Preserve outputs already emitted before an error and do not catch errors raised outside the handler's scope.
Programmatic Acceptance
=== AC control-corpus ===
Intent: Conditional and alternative expressions execute the selected corpus cases with jq truth and stream semantics.
Suite: scoped
Requires: executable=python3; scope=test
Probe: --list
Probe Count: summary
import json import os import subprocess import sys
SELECT = r"^\[if (1,null,2|empty|1|null) then|^\[if (true|false) then|^if false then 3" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] print(f"{tally['pass']} passed, {tally['fail']} failed, {tally['error']} errored") assert sum(tally.values()) > 0 assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC control-corpus ===
User Acceptance
- None.
Guardrails
- Preserve partial output and lexical error boundaries.
- Defer selected cases requiring functions or other later capabilities to scoped integration.