Fix streaming error parsing crash on non-Hash JSON error bodies - #840
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #840 +/- ##
==========================================
+ Coverage 95.44% 95.50% +0.06%
==========================================
Files 182 182
Lines 9106 9124 +18
Branches 1480 1490 +10
==========================================
+ Hits 8691 8714 +23
+ Misses 188 184 -4
+ Partials 227 226 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Niraj22
added a commit
to Niraj22/ruby_llm
that referenced
this pull request
Jul 25, 2026
Codecov flagged 4 uncovered lines on PR crmne#840: the Hash-shaped-error fallback in the anthropic protocol (type other than overloaded_error) and the server_error/default branches in the chat_completions protocol were never exercised by the regression specs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
20 tasks
crmne
pushed a commit
to Niraj22/ruby_llm
that referenced
this pull request
Aug 10, 2026
Codecov flagged 4 uncovered lines on PR crmne#840: the Hash-shaped-error fallback in the anthropic protocol (type other than overloaded_error) and the server_error/default branches in the chat_completions protocol were never exercised by the regression specs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
crmne
force-pushed
the
fix-streaming-error-non-hash-body
branch
from
August 10, 2026 21:26
9feec2d to
8d87a4a
Compare
parse_streaming_error assumed the error body parses to a Hash with a
Hash 'error' value. A bare JSON string body, or a string error value
like {"error": "msg"} (xAI/Grok shape), crashed with TypeError:
String does not have #dig instead of surfacing the provider's message.
Guard the body shape before digging, in the chat_completions, anthropic
and gemini protocols plus the default fallback. Untyped bodies return a
nil status so the real HTTP status from the response env wins.
Fixes crmne#837
Codecov flagged 4 uncovered lines on PR crmne#840: the Hash-shaped-error fallback in the anthropic protocol (type other than overloaded_error) and the server_error/default branches in the chat_completions protocol were never exercised by the regression specs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
crmne
force-pushed
the
fix-streaming-error-non-hash-body
branch
from
August 10, 2026 21:39
8d87a4a to
c49fe9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Fixes #837. When a streaming request fails and the error body parses to something other than the typed
{"error": {"type": …, "message": …}}hash — a bare JSON string, or a string error value like{"error": "msg"}(xAI/Grok shape) —parse_streaming_errorcrashed withTypeError: String does not have #dig methodinstead of surfacing the provider's message. The same bodies were already handled fine on the non-streaming path.The old guard
return unless error_data['error']did substring matching on string bodies (String#[]), anddig('error', 'type')recursed into string error values — hence the crash.This adds shape guards before the hash lookups in the
chat_completions,anthropic, andgeminiprotocols plus the default fallback inStreaming. Untyped bodies return anilstatus sobuild_stream_error_responsefalls back to the real HTTP status; the user-facing message still comes fromProvider#parse_error, which already handles string bodies.Type of change
How tested
Regression specs per protocol (typed object, bare string body, string error value) plus end-to-end specs through
handle_failed_responseasserting the provider's actual message surfaces in the raised error. Full suite: 1889 examples, 0 failures.