Repository navigation
fix: print empty and non-JSON api responses correctly - #78
Conversation
equinix api ignored the json.Unmarshal error and re-marshalled the nil value, so a 204 No Content or a plain-text body was printed as "null". Print nothing for an empty body and the body as it is when it is not JSON. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
ramseydsilva
left a comment
There was a problem hiding this comment.
The fix's shape is right: early-return on empty, pass through on unparseable, leave the JSON path untouched.
|
Reviewed this by building the branch and running it, not just reading the diff. The diagnosis is exact: on The shape of the fix looks right to me — early-return on an empty body, pass through on an unparseable one, leave the JSON path untouched. Two small, non-blocking notes:
I also filed #88 for two adjacent "silently discards output" bugs that are out of scope here: AI disclosure: reviewed with the help of Claude Code. |
|
This PR is included in version 0.6.0 🎉 |
equinix apiprintednullfor any response that was not JSON. Incmd/api.gothe error fromjson.Unmarshal(resp, &raw)was overwritten by the followingjson.MarshalIndent(raw, ...), which happily marshals the nilraw:So a successful DELETE looked like it returned something, and a text or HTML body (an error page from a proxy, a health endpoint) was lost.
Fix
--format json|yamlpath unchanged.Testing
cmd/api_output_test.goaddsTestE2E_APIEmptyResponsePrintsNothingandTestE2E_APINonJSONResponseIsPrintedAsIs. They run the real root command against a local fake API (redirectTransportandrunCLIfrome2e_test.go). Both print"null\n"onmainand fail; with the fix they pass.go test ./...,go vet ./...andgolangci-lint run ./cmd/are clean.This is separate from the
--datarequest body fix and touches a different file, so the two can be merged in either order.AI disclosure: written with the help of Claude Code, reviewed and tested by me.