fix(cli): JSON error envelope on parse failure under --format json (#500)#535
Open
avrabe wants to merge 1 commit into
Open
fix(cli): JSON error envelope on parse failure under --format json (#500)#535avrabe wants to merge 1 commit into
avrabe wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Rivet Criterion Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: f0c316e | Previous: 6b160cf | Ratio |
|---|---|---|---|
traceability_matrix/1000 |
58825 ns/iter (± 230) |
45348 ns/iter (± 269) |
1.30 |
query/10000 |
330478 ns/iter (± 1877) |
232848 ns/iter (± 5826) |
1.42 |
This comment was automatically generated by workflow using github-action-benchmark.
📐 Rivet artifact delta
Graphgraph LR
REQ_219["REQ-219"]:::added
classDef added fill:#d4edda,stroke:#28a745,color:#155724
classDef removed fill:#f8d7da,stroke:#dc3545,color:#721c24
classDef modified fill:#fff3cd,stroke:#ffc107,color:#856404
classDef overflow fill:#e2e3e5,stroke:#6c757d,color:#495057,stroke-dasharray: 3 3
Added
Posted by |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…json (REQ-219, #500) rivet's top-level `--project`/`--schemas` are not clap `global` args, so they parse only before the subcommand. `rivet validate --project X` is a parse error; clap writes it to stderr and leaves stdout empty, so a `--format json` consumer (e.g. a subprocess from #488) got an empty payload and a cryptic "EOF while parsing a value" with no hint about the arg position. The obvious `global = true` fix is a known trap — it debug-asserts against positional subcommands and broke main once (REQ-209/#501, reverted #502). Fix (no `global`): parse via `Cli::try_parse()`; on error, when argv requested JSON (`--format json`/`-f json`, any spelling), print a one-line `{ "error", "hint" }` envelope on stdout (hint: pass --project/--schemas BEFORE the subcommand), then still emit clap's human message to stderr and exit with clap's code. `--help`/`--version` pass through (exit 0); non-JSON parse errors keep the stderr-only behavior (empty stdout). Confirmed with the new `json_consumers_get_an_error_envelope_on_parse_failure` integration test and `cargo test -p rivet-cli --test cli_commands` (132 pass); `cargo fmt --check` + `cargo clippy --all-targets -- -D warnings` clean; `rivet validate` PASS. Implements: REQ-219 Refs: REQ-007 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
f0c316e to
7b2e84b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
rivet's top-level
--project/--schemasare not clapglobalargs, so they only parse before the subcommand:rivet --project X validaterivet validate --project X→ clap parse errorclap writes that error to stderr and leaves stdout empty, so a
--format jsonconsumer (e.g. the subprocess in #488) got an empty payload and a crypticEOF while parsing a value, with no hint that the arg position was the cause.Why not
global = trueThe issue suggests
global = true, but that's a known trap in this repo:globaldebug-asserts against positional subcommands and brokemainonce (REQ-209 / #501, reverted in #502). So this takes the safe, additive route instead.How
Parse via
Cli::try_parse(); on error, when argv requested JSON (--format json/-f json, all spellings), print a one-line envelope on stdout:{"error":"unexpected argument '--project' found","hint":"rivet's top-level options are not positional-global: pass --project/--schemas BEFORE the subcommand, e.g. `rivet --project <dir> <subcommand>`"}…then still emit clap's normal human message to stderr and exit with clap's code.
--help/--versionpass through (exit 0); non-JSON parse errors keep the stderr-only behavior (empty stdout, unchanged).Tests
New
json_consumers_get_an_error_envelope_on_parse_failure: misplaced--project --format json→ valid JSON envelope on stdout witherror+hint(exit ≠ 0); the same without JSON → empty stdout.cargo test -p rivet-cli --test cli_commands132 pass; clippy--all-targets -D warnings+ fmt clean.Closes #500. Implements REQ-219.
🤖 Generated with Claude Code