Repository navigation
io.sh: API errors use the CLI's error JSON when jq is present - #32
Merged
Merged
Conversation
) call() printed the API's error body as it came, so a WordPress error such as {code, message, data: {status}} reached stderr in that shape while io.sh's own errors and the CLI's used {ok: false, error, message}. With jq, call() now builds the same object as the CLI's api(): error from .error or .code (http_<status> for a body that is not JSON), message, status, and the extra fields the CLI copies. Without jq the body is still passed through unchanged, as documented. Test: test/api-error-shape.test.mjs compares io.sh and the CLI on eight kinds of API error from the REST stub.
Contributor
Author
|
Review by Grok Bot (Indian Opinion QA agent) Tested at head Fixes: #29. With jq, API errors from What I checked
Not checked
ReviewNothing blocking. Defining Automated checks (this head vs current main)
I'm Grok Bot, the automated QA agent for Indian Opinion. This is a comment-only review. I don't approve, request changes or merge. Local stack: PHP 8.4.28, Composer 2.11.3, MariaDB 11.8.9, Node 24.22.1, WordPress 7.1.5. |
makriman
marked this pull request as ready for review
December 5, 2026 20:05
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.
Problem
With jq installed,
io.shpromises the same JSON as the CLI. Errors that come back from the API do not get it.io brief 99999999999exits 4 (correct) but prints the API's own body on stderr:The CLI prints
{"ok":false,"error":"io_not_found","message":"No such article.","status":404}.io.sh's own client-side errors already use the CLI shape, so a script reading.okor.errormissed only the errors that came from the API.Root cause
call()inio.shmapped the HTTP status to an exit code and then printed$outto stderr unchanged. Nothing reshaped the error path. The success path was already reshaped with jq.Change
With jq,
call()builds the same object asapi()inbin/indianopinion.mjs:error: the body'serror, else itscode, elsehttp_<status>message: the body'smessage, elseHTTP <status>, with the CLI's own text forrest_no_routestatus: the HTTP statusfield,allowed,attempts_left,suggestion,options,scopeandretry_after, when the body has themA body that is not JSON, for example an HTML error page, gives
http_<status>as in the CLI. If jq itself fails, the raw body is printed, as before. Without jq nothing changes: the README says that without jqio.shprints the API's JSON unchanged, and that stays true. README and theio.shheader now say that API errors are reshaped with jq.CHANGELOG.mdhas an Unreleased entry.Tests
test/api-error-shape.test.mjs(innpm test) runs the CLI andio.shside by side against the REST stub and requires the same exit code and the same stderr object for eight kinds of API error: the WordPress-style 404 from the issue, a 400 withattempts_left, a 400 withfield, a 429 withretry_afterandscope, a 409ambiguouswithoptions, a refused token (401), an agent API 404,rest_no_route, and an HTML 404. A third test pins the no-jq behaviour (body unchanged). Before the fix the first two tests fail.Commands run on this branch:
npm test(Node 22.23.4, jq 1.7,../mcpinstalled): 35 tests, 35 pass, 0 skipped.npm pack --dry-run: the same 6 files.For the reviewer
test/stub-rest.mjs), which follow the agent API contract and WordPress's REST error format. I did not re-check the live API's error shapes for this change.Retry-Afterfrom the response header first;io.shdoes not read headers, so it uses the body'sretry_afteronly. The stub sends both, as the API contract does. If the live API ever sends the header without the body field,io.shwill leaveretry_afterout."ok": falseas an error;io.shdoes not. I left that alone because I have no evidence the API sends such answers.Fixes #29