fix(on-call): handle empty 200 body in pages get#671
Draft
platinummonkey wants to merge 1 commit into
Draft
Conversation
GET /api/v2/on-call/pages/{id} can return HTTP 200 with an empty body
(content-length: 0). parse_response_json fed the empty body straight to
serde_json, producing "EOF while parsing value at line 1 column 0" and
failing `pup on-call pages get`.
Treat an empty or whitespace-only success body as JSON null in the shared
parse_response_json helper, so every raw_* caller (raw_get/raw_post/etc.)
degrades gracefully instead of crashing, mirroring the existing 204
No Content handling.
- Guard empty/whitespace bodies in raw_client::parse_response_json
- Add raw_get unit tests (empty, whitespace-only, valid JSON)
- Add pages_get regression test for empty 200 body
Closes #638
Contributor
|
I can only run on private repositories. |
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 does this PR do?
Fixes
pup on-call pages get <id>failing withError: failed to get page: EOF while parsing value at line 1 column 0.The Datadog
GET /api/v2/on-call/pages/{id}endpoint can return HTTP 200 with an empty body (content-length: 0). The sharedparse_response_jsonhelper in src/raw_client.rs passed those empty bytes straight to serde_json, which errored on the missing JSON value. That helper backsraw_get,raw_post,raw_put, and every other hand-written raw HTTP call, so the crash could hit any endpoint returning an empty success body.An empty or whitespace-only success body is now treated as JSON null, mirroring the existing 204 No Content handling already present in
raw_putandraw_request.Motivation
Reported in issue #638:
pup on-call pages getnever returns the page and instead errors out. The reporter confirmed viapup api -i v2/on-call/pages/<id>that the endpoint responds 200 with content-length: 0, so the body is genuinely empty and the client must not treat that as a parse failure.Changes
parse_response_json, returningserde_json::Value::Nullinstead of failing to parse.raw_getunit tests for an empty body, a whitespace-only body, and a valid JSON body (the last ensures the new guard does not shadow normal parsing).test_on_call_pages_get_empty_bodyforpages_getreceiving an empty 200 body.Testing
test_on_call_pages_get_empty_body(src/commands/on_call.rs).pages_gettests (success, 404 not found, percent-encoded id) continue to cover the non-empty and error paths.cargo fmt --checkpasses.cargo test/cargo clippycould not be executed in this sandbox because the pinneddatadog-api-clientgit dependency is outside the environment's network allowlist; CI will exercise them.Additional Notes
The fix is centralized in
parse_response_jsonrather than special-cased in the on-call command, so other raw endpoints that return empty success bodies benefit from the same graceful handling.Checklist
Related Issues
Closes #638
PR by Bits - View session in Datadog
Comment @DataDog to request changes