fix(uptime): only download body if necessary#487
Conversation
We're always downloading the body now, because we want to capture it on potential errors. We only need the body if there is an error, though, and most of our checks via assertions won't need the body bytes, either. This reorganizes the code a bit to only download the body once, and only when necessary, either for assertion execution, or for error capture.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| scheduled_check.get_config().subscription_id, | ||
| err.to_string(), | ||
| ); | ||
| return Check::assert_compile_failure(&err); |
There was a problem hiding this comment.
Early return drops body bytes, re-download gets nothing
Low Severity
When an assertion with requires_body() == true fails to compile, body bytes are consumed from the response stream inside to_check_result but then dropped by the early return Check::assert_compile_failure. The returned Check has body_bytes: None. Back in check_url, if capture is desired, read_body_bounded attempts to re-read the already-consumed response stream and gets empty data. The old code didn't have this problem because body was downloaded in check_url scope before calling to_check_result.


We're always downloading the body now, because we want to capture it on potential errors. We only need the body if there is an error, though, and most of our checks via assertions won't need the body bytes, either. This reorganizes the code a bit to only download the body once, and only when necessary, either for assertion execution, or for error capture.