Skip to content

Conversation

@Ratish1
Copy link
Contributor

@Ratish1 Ratish1 commented Oct 21, 2025

Description

Avoid a raw JSONDecodeError when the Gemini API returns an empty or non-JSON error message (for example on an invalid API key).

This PR:

  • Catches json.JSONDecodeError when parsing error.message, logs a warning with context (error_message=<...> | Gemini API returned non-JSON error), and re-raises the original genai.errors.ClientError with the JSON error as the explicit cause.

  • Adds a unit test (test_stream_handles_non_json_error) to verify a non-JSON error is logged and the original ClientError is propagated

Related Issues

#1024

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare
  • I ran hatch fmt --formatter and hatch fmt --linter
  • I ran the unit test: pytest -q tests/strands/models/test_gemini.py::test_stream_handles_non_json_error -> passed

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Ratish1
Copy link
Contributor Author

Ratish1 commented Oct 30, 2025

Hello @dbschmigelski , can the github actions be run with your approval, so the workflow passes. Thanks.

@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dbschmigelski dbschmigelski merged commit 89bab98 into strands-agents:main Nov 4, 2025
13 checks passed
@Ratish1 Ratish1 deleted the jsonerror branch November 6, 2025 11:41
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.

3 participants