stream_generate_content ends silently on a non-2xx response #3
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
GeminiClient::stream_generate_contentdoesn't check the HTTP status. When Vertex rejects a request (for example a 400 for an invalid function declaration), the response body is a plain JSON error, not SSE.response.event_stream()finds nodata:lines, so the returned stream yields no items and ends cleanly. The caller can't tell a rejected request from an empty answer, and nothing is logged.generate_contentdoesn't have this problem: it parses the body asGenerateContentResponse, whoseErrorvariant becomes anErr.Reproduction
Found while working on andreban/znotes#382 (2026-10-18,
gemini-3.8-flash,v1beta1).stream_generate_contenta request with a function declaration that Vertex rejects, for exampleparameters: {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": {"q": {"type": "string"}}}.{"error": {"code": 400, "message": "Invalid JSON payload received. Unknown name \"$schema\" at 'tools[0].function_declarations[0].parameters': Cannot find field.", "status": "INVALID_ARGUMENT"}}./api/agent/chatthen returns HTTP 200 with an empty body and logs nothing, so the user sees an empty turn.Cause
In
src/client.rs,stream_generate_contentdoes:The status is never checked before the body is read as SSE.
Suggested fix
Before building the event stream, check
response.status(). On a non-success status, read the body and return anErr, parsing it asGenerateContentResponseErrorwhen possible (asgenerate_contentdoes) and falling back to the status and raw text. Add a test for a 400 JSON body.