Skip to content

fix(consume): guard message viewer against empty-body response crash - #3445

Open
Dave Shoup (shouples) wants to merge 1 commit into
mainfrom
djs/issue-776-consume-empty-response-body
Open

fix(consume): guard message viewer against empty-body response crash#3445
Dave Shoup (shouples) wants to merge 1 commit into
mainfrom
djs/issue-776-consume-empty-response-body

Conversation

@shouples

Copy link
Copy Markdown
Contributor

Summary of Changes

Closes #776.

The topic message viewer sometimes stops reacting to server errors while polling: the stream keeps running and no "Authentication required" / "Insufficient permissions" / "Topic not found" notification appears, while the underlying SyntaxError: Unexpected end of JSON input shows up in Sentry (VSCODE-EXTENSION-AJ).

The cause: the error handler called error.response.json() directly to read the response body. An empty response body makes that throw, and the throw escapes the catch block before it can pause the stream or notify the user.

This routes the parse through the existing extractResponseBody() helper (src/errors.ts), which already falls back to .text() when .json() fails. An empty body now resolves to "" instead of throwing, so the existing status-based handling (pause and notify) runs as intended. Five other call sites already use this helper for the same reason.

Click-testing instructions

Not directly click-testable (the trigger is an intermittent empty-body error response from the server). Verified via unit test instead: npx gulp test -t "extractResponseBody".

Optional: Any additional details or context that should be provided?

  • Before: empty-body error response → SyntaxError escapes the catch block → stream keeps running, no user notification, Unexpected end of JSON input in Sentry.
  • After: empty-body error response → payload falls back to "" → status-based handling runs, stream pauses on 4xx, user is notified.
  • Follow-up (out of scope): six other call sites still call error.response.json() directly and carry the same latent empty-body crash (topics.ts, kafkaClusters.ts, scaffoldUtils.ts, schemaManagement/upload.ts, loaderUtils.ts, sidecar/middlewares.ts); worth a separate cleanup pass.
  • Test coverage: src/consume.ts has no co-located test file, so this is covered at the extractResponseBody() helper level rather than through the message-viewer catch block.

Pull request checklist

Please check if your PR fulfills the following (if applicable):

Tests

  • Added new
  • Updated existing
  • Deleted existing

Release notes

  • Does anything in this PR need to be mentioned in the user-facing CHANGELOG?

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 27, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents the topic message viewer’s polling loop from silently breaking on empty-body HTTP error responses by routing response parsing through the shared extractResponseBody() helper, and adds a targeted unit test to lock in the empty-body behavior.

Changes:

  • Use extractResponseBody(error) instead of error.response.json() in the message viewer polling error handler to avoid Unexpected end of JSON input escaping the catch block.
  • Add a unit test asserting extractResponseBody() returns "" for an empty response body.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/consume.ts Switches message-viewer polling error handling to defensive response-body extraction to avoid empty-body JSON parse crashes.
src/errors.test.ts Adds coverage ensuring extractResponseBody() safely returns an empty string for empty response bodies.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sonarqube-confluent

Copy link
Copy Markdown

@shouples
Dave Shoup (shouples) marked this pull request as ready for review August 28, 2026 20:53
@shouples
Dave Shoup (shouples) requested a review from a team as a code owner August 28, 2026 20:53
@shouples
Dave Shoup (shouples) enabled auto-merge (squash) August 28, 2026 20:53
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.

Intermittent syntax error in consume.ts - Unexpected end of JSON input

2 participants