Unexpected end of json #4681

Closed
opened 2026-02-16 17:45:01 -05:00 by yindo · 3 comments
Owner

Originally created by @Davincible on GitHub (Jan 10, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Image

Seems like https://github.com/anomalyco/opencode/pull/7618 is the fix

Plugins

No response

OpenCode version

1.1.10

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @Davincible on GitHub (Jan 10, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description <img width="1957" height="345" alt="Image" src="https://github.com/user-attachments/assets/fc4a67d4-b9a6-4554-bae4-86f8dc940eb1" /> Seems like https://github.com/anomalyco/opencode/pull/7618 is the fix ### Plugins _No response_ ### OpenCode version 1.1.10 ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:45:01 -05:00
yindo closed this issue 2026-02-16 17:45:01 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 10, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #2188: JSON parsing failed: Text
  • #1803: [aws bedrock: anthropic opus 4.1] The arguments provided to the tool are invalid: Invalid input for tool write: JSON parsing failed: Text
  • #3034: task tool "SyntaxError: Unexpected end of JSON input"
  • #7692: [Bug] JSON Parse Error with Zhipu GLM-4.7: Stream chunks are concatenated incorrectly
  • #5890: Incomplete JSON when writing out files

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 10, 2026): This issue might be a duplicate of existing issues. Please check: - #2188: JSON parsing failed: Text - #1803: [aws bedrock: anthropic opus 4.1] The arguments provided to the tool are invalid: Invalid input for tool write: JSON parsing failed: Text - #3034: task tool "SyntaxError: Unexpected end of JSON input" - #7692: [Bug] JSON Parse Error with Zhipu GLM-4.7: Stream chunks are concatenated incorrectly - #5890: Incomplete JSON when writing out files Feel free to ignore if none of these address your specific case.
Author
Owner

@coleleavitt commented on GitHub (Jan 11, 2026):

I've submitted a fix for this in #7888.

Root cause: The SDK's client.gen.ts only handles empty responses when status === 204 or Content-Length === "0". When the server returns an empty body with status 200 and no Content-Length header, response.json() throws "Unexpected end of JSON input".

Fix:

  1. Read response as text first, only parse JSON if non-empty
  2. Added try-catch with contextual error messages
  3. Fixed server OPTIONS handler to return proper 204 status

This is a more complete fix than #7618 - it prevents the crash entirely rather than just improving the error message.

@coleleavitt commented on GitHub (Jan 11, 2026): I've submitted a fix for this in #7888. **Root cause**: The SDK's `client.gen.ts` only handles empty responses when `status === 204` or `Content-Length === "0"`. When the server returns an empty body with status 200 and no Content-Length header, `response.json()` throws "Unexpected end of JSON input". **Fix**: 1. Read response as text first, only parse JSON if non-empty 2. Added try-catch with contextual error messages 3. Fixed server OPTIONS handler to return proper 204 status This is a more complete fix than #7618 - it prevents the crash entirely rather than just improving the error message.
Author
Owner

@mrlubos commented on GitHub (Jan 13, 2026):

@Davincible this should be handled upstream https://github.com/hey-api/openapi-ts/pull/3202

@mrlubos commented on GitHub (Jan 13, 2026): @Davincible this should be handled upstream https://github.com/hey-api/openapi-ts/pull/3202
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4681