Raise `BedrockEmbeddingModel` errors as `ModelHTTPError`/`ModelAPIError` instead of an `ExceptionGroup`, and map botocore transport errors

Merged
DO
2mo ago
+99-27

Related: #8722. I found this while auditing how each provider adapter maps its errors.

A failed BedrockEmbeddingModel request didn't surface as the ModelHTTPError or ModelAPIError that BedrockConverseModel raises for the same failure:

  • Every error escaped wrapped in an ExceptionGroup from the anyio task group in _embed_concurrent, even for a single input. So except ModelHTTPError / except ModelAPIError never matched: a throttled embed_query() raised ExceptionGroup([ModelHTTPError(429)]).
  • botocore transport failures (ReadTimeoutError, EndpointConnectionError) weren't mapped at all. Only ClientError was.

Changes:

  • _embed_concurrent now runs its requests through the existing _utils.gather, which cancels queued requests on the first failure. In-flight requests run in threads that can't be cancelled, so a throttle or validation error usually fails several of them. When that happens, the first model error is raised on its own.
  • _invoke_model maps HTTPClientError and botocore's ConnectionError to ModelAPIError, using the same clause as models/bedrock.py's _map_api_errors.

New public surface: none.

What changes for existing users: A failed Bedrock embedding request now raises ModelHTTPError / ModelAPIError directly instead of an ExceptionGroup holding one of them. Code that caught the group with except* ModelHTTPError keeps working; code that caught it with except ExceptionGroup does not. Transport errors raise ModelAPIError instead of the raw botocore exception.

Verification

  • tests/test_embeddings.py::TestBedrock::test_client_error_with_status_code and ::test_client_error_without_status_code previously asserted the ExceptionGroup wrapping; they now assert the bare exception.
  • tests/test_embeddings.py::TestBedrock::test_client_error_on_every_concurrent_request: a 429 on every one of 3 concurrent requests raises one ModelHTTPError.
  • tests/test_embeddings.py::TestBedrock::test_transport_error covers [read-timeout] and [endpoint-connection].
  • Reverting the source change makes all 5 tests fail.

A 200 with a non-JSON body still raises json.JSONDecodeError. That's the same class of bug as #8843, and I've left it for follow-up alongside #8846.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code