From 4c3ff7ddaef640bb049dcb4b956955c0b322f1f0 Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Sun, 12 Apr 2026 05:43:03 +0800 Subject: [PATCH] fix: narrow Bedrock _init_clients except to credential errors only The bare `except Exception` would silently swallow `TypeError`, `AttributeError`, and other real bugs in `_build_sync_client` with only a debug log. The intent is to defer on missing AWS credentials, which boto3 surfaces as `BotoCoreError` / `ClientError` (and `ValueError` for some validation paths). Catch only those; let everything else propagate so genuine failures stay loud. --- lib/crewai/src/crewai/llms/providers/bedrock/completion.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py index c7676c778..5932b66f0 100644 --- a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py +++ b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py @@ -310,10 +310,14 @@ class BedrockCompletion(BaseLLM): """Eagerly build the sync client when AWS credentials resolve, otherwise defer so ``LLM(model="bedrock/...")`` can be constructed at module import time even before deployment env vars are set. + + Only credential/SDK errors are caught — programming errors like + ``TypeError`` or ``AttributeError`` propagate so real bugs aren't + silently swallowed. """ try: self._client = self._build_sync_client() - except Exception as e: + except (BotoCoreError, ClientError, ValueError) as e: logging.debug("Deferring Bedrock client construction: %s", e) self._async_exit_stack = AsyncExitStack() if AIOBOTOCORE_AVAILABLE else None return self