Skip to content

fix(errors): never print a blank error for an empty response body - #232

Merged
eddietejeda merged 1 commit into
mainfrom
fix/blank-error-messages
Jul 20, 2026
Merged

fix(errors): never print a blank error for an empty response body#232
eddietejeda merged 1 commit into
mainfrom
fix/blank-error-messages

Conversation

@eddietejeda

Copy link
Copy Markdown
Contributor

Problem

During the #230 load tests, a small fraction of requests (~0.02–0.06% at 32–1024-way concurrency) failed with stderr containing only ANSI color codes — an invisible error message with exit 1. Root cause: a dropped connection or bodyless 5xx yields an empty response body; util::api_error echoes the body verbatim when it isn't JSON/HTML, and the print paths render red("").

Fix

  • util::api_error: an empty/whitespace body falls back to unexpected empty response from server — covers every caller, including the direct api_error(...).red() prints in databases.rs.
  • sdk::format_fail_message: with an empty body the HTTP status is the only signal available, so it's surfaced: error: HTTP 502 Bad Gateway (empty response body). This is the path ApiError::print()/exit() uses, i.e. what databases create failures under load hit.

ApiError::Transport messages were audited too — every construction site prefixes them, so they can't be blank.

Tests

  • api_error_never_returns_blank_for_empty_body
  • format_fail_message_empty_body_surfaces_status
  • Full suite: 308 passed, 0 failed.

Follow-up from #230 (second follow-up there — un-timeouted Client::new() in auth.rs/credentials.rs — still open).

Under heavy load a small fraction of requests (~0.02-0.06%) failed with
an error line that was nothing but ANSI color codes: a dropped
connection or bodyless 5xx produced an empty body, api_error() echoed
it verbatim, and print paths rendered red("") — invisible output with
exit 1.

- util::api_error: empty/whitespace body now falls back to 'unexpected
  empty response from server' (covers every caller, including the
  direct api_error(...).red() prints in databases.rs).
- sdk::format_fail_message: when the body is empty the HTTP status is
  the only signal there is, so surface it: 'error: HTTP 502 Bad Gateway
  (empty response body)'.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean, well-scoped fix with tests covering both empty and whitespace-only bodies. The two-layer handling (api_error for all callers, format_fail_message surfacing the HTTP status) is sensible and correctly ordered.

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@eddietejeda
eddietejeda merged commit 193320e into main Jul 20, 2026
14 checks passed
@eddietejeda
eddietejeda deleted the fix/blank-error-messages branch July 20, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant