Skip to content

fix(on-call): handle empty 200 body in pages get#671

Draft
platinummonkey wants to merge 1 commit into
mainfrom
dd/fix/on-call-pages-get-empty-body
Draft

fix(on-call): handle empty 200 body in pages get#671
platinummonkey wants to merge 1 commit into
mainfrom
dd/fix/on-call-pages-get-empty-body

Conversation

@platinummonkey

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes pup on-call pages get <id> failing with Error: 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 shared parse_response_json helper in src/raw_client.rs passed those empty bytes straight to serde_json, which errored on the missing JSON value. That helper backs raw_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_put and raw_request.

Motivation

Reported in issue #638: pup on-call pages get never returns the page and instead errors out. The reporter confirmed via pup 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

  • src/raw_client.rs: guard empty/whitespace-only bodies in parse_response_json, returning serde_json::Value::Null instead of failing to parse.
  • src/raw_client.rs: add raw_get unit 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).
  • src/commands/on_call.rs: add regression test test_on_call_pages_get_empty_body for pages_get receiving an empty 200 body.

Testing

  • Positive tests: empty body -> null and whitespace-only body -> null (src/raw_client.rs).
  • Negative/contrast test: a valid JSON body still parses correctly (src/raw_client.rs).
  • Regression test reproducing issue [BUG] on-call pages get returning EOF while parsing value at line 1 column 0 #638: test_on_call_pages_get_empty_body (src/commands/on_call.rs).
  • Existing pages_get tests (success, 404 not found, percent-encoded id) continue to cover the non-empty and error paths.
  • cargo fmt --check passes. cargo test / cargo clippy could not be executed in this sandbox because the pinned datadog-api-client git dependency is outside the environment's network allowlist; CI will exercise them.

Additional Notes

The fix is centralized in parse_response_json rather than special-cased in the on-call command, so other raw endpoints that return empty success bodies benefit from the same graceful handling.

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

Related Issues

Closes #638


PR by Bits - View session in Datadog

Comment @DataDog to request changes

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
@datadog-datadog-prod-us1-2

Copy link
Copy Markdown

View session in Datadog

Bits Code status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

@datadog-datadog-prod-us1

Copy link
Copy Markdown
Contributor

I can only run on private repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] on-call pages get returning EOF while parsing value at line 1 column 0

2 participants