Skip to content

Structured JSON error envelope + status propagation to scripts/pipe #6578

Open
notxvilka wants to merge 4 commits into
devfrom
asan-error-envelope
Open

Structured JSON error envelope + status propagation to scripts/pipe #6578
notxvilka wants to merge 4 commits into
devfrom
asan-error-envelope

Conversation

@notxvilka

Copy link
Copy Markdown
Contributor

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description

Largely mechanistic change of adding an envelope and optionally reporting status for JSON commands, covering the A1 of the "AI issue" - machine detectable errors: #6543

Test plan

Ci is green

Closing issues

Partially addresses #6543

@notxvilka notxvilka added this to the 1.0.0 milestone Jun 29, 2026
@github-actions github-actions Bot added rizin rz-test API RzCore AI/LLM Partially or fully AI generated. Critical thinking is advised! labels Jun 29, 2026
Comment thread test/db/cmd/cmd_error_reporting
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.32143% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.94%. Comparing base (155ead6) to head (3166169).

Files with missing lines Patch % Lines
librz/core/cmd/cmd_api.c 66.15% 17 Missing and 5 partials ⚠️
librz/core/cmd/cmd.c 73.91% 4 Missing and 2 partials ⚠️
librz/core/cmd_descs/cmd_descs.c 50.00% 0 Missing and 2 partials ⚠️
librz/main/rizin.c 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
librz/core/cconfig.c 80.29% <100.00%> (+0.01%) ⬆️
librz/core/core.c 60.56% <100.00%> (+0.02%) ⬆️
librz/include/rz_cmd.h 71.42% <ø> (ø)
librz/main/rizin.c 50.05% <94.11%> (+0.25%) ⬆️
librz/core/cmd_descs/cmd_descs.c 50.63% <50.00%> (-0.01%) ⬇️
librz/core/cmd/cmd.c 64.95% <73.91%> (+0.09%) ⬆️
librz/core/cmd/cmd_api.c 67.92% <66.15%> (-0.12%) ⬇️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 155ead6...3166169. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread librz/core/cmd/cmd.c Outdated
Comment thread librz/core/cconfig.c Outdated
Comment thread librz/main/rizin.c Outdated
Comment thread librz/main/rizin.c Outdated
XVilka added 4 commits July 5, 2026 23:45
* Add the `rz_cmd_status_tostring` API that maps an `RzCmdStatus` to a
  stable, machine-readable string (`OK`, `WRONG_ARGS`, `ERROR`,
  `INVALID`, `NONEXISTINGCMD`, `EXIT`).
* Record the status of every executed command in a new
  `RzCore.last_cmd_status` field, so consumers driving Rizin can read
  back whether the command that just ran succeeded or failed.

Co-authored-by agent: Claude/claude-opus-4-8
* Turn the root `_` (last output) command into a "Last command
  introspection" group and add a `_s`/`_sj` subcommand that prints the
  status of the previously executed command from `RzCore.last_cmd_status`.
* `_s` prints the stable status code while `_sj` reports it as a JSON
  object together with the integer code from `rz_cmd_status2int`, so an
  agent driving Rizin over rzpipe can query success or failure explicitly.

Co-authored-by agent: Claude/claude-opus-4-8
When a command is invoked in a JSON output mode and the `cfg.json.status`
config is enabled, emit a machine-readable status object on stdout after
the command's own output, so a consumer driving Rizin over rzpipe or
`rizin -c` can reliably tell success from failure (and a failure from an
empty-but-successful result). The envelope is reported consistently for
every command, so the trailing object is always present and only its
`error` field changes: `{"error":null}` on success and
`{"error":{"code":"WRONG_ARGS","message":"...","command":"afl"}}` on
failure.

* Gate the behavior behind the new `cfg.json.status` config (default
  `false`). Reporting the envelope for every JSON command changes their
  output, so keeping it opt-in preserves the current behavior while
  letting agents enable structured status reporting.
* The error object reuses `rz_cmd_status_tostring` for the stable `code`
  and reports the canonical command name without the mode suffix.

Co-authored-by agent: Claude/claude-opus-4-8
Optionally make `rizin -q`/`-c`/`-i` exit with a non-zero process code
when a command fails, so that shells and CI can detect errors instead of
always seeing a successful exit.

* Gate the behavior behind the new `cfg.exit.errorcode` config (default
  `false`) to preserve the historical behavior of always exiting with 0
  in batch mode.
* `run_commands` now reports whether any executed command returned a
  failing status (non-OK and non-EXIT); the process exit code is set to
  1 from that result only when the config is enabled. A `q`/quit request
  is treated as success.

Co-authored-by agent: Claude/claude-opus-4-8
@notxvilka notxvilka force-pushed the asan-error-envelope branch from 4d6ff66 to 3166169 Compare July 5, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI/LLM Partially or fully AI generated. Critical thinking is advised! API rizin rz-test RzCore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants