Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(errors): catch SDK-specific connection/timeout error classes

xf gong6e41640f809f
diff --git a/cubepi/errors.py b/cubepi/errors.py
index 1991f26..1143402 100644
--- a/cubepi/errors.py
+++ b/cubepi/errors.py
@@ -253,6 +253,15 @@ def classify_and_raise(
msg, provider=provider, model=model_id, status_code=status
) from exc
+ # SDK-specific connection/timeout errors (openai.APIConnectionError,
+ # anthropic.APITimeoutError) don't inherit from Python's built-in
+ # ConnectionError/TimeoutError, so the isinstance above misses them.
+ cls_name = type(exc).__name__
+ if "ConnectionError" in cls_name or "Timeout" in cls_name:
+ raise ProviderUnavailable(
+ msg, provider=provider, model=model_id, status_code=status
+ ) from exc
+
if status is not None and 500 <= status < 600:
raise ProviderUnavailable(
msg, provider=provider, model=model_id, status_code=status
diff --git a/tests/test_errors.py b/tests/test_errors.py
index e080e88..bc30638 100644
--- a/tests/test_errors.py
+++ b/tests/test_errors.py
@@ -345,3 +345,19 @@ class TestRetryAfterFrom:
"rate limited", status_code=429, headers={"retry-after": "not-a-number"}
)
assert _retry_after_from(exc) is None
+
+
+class TestSDKConnectionErrors:
+ """SDK-specific connection/timeout exceptions masquerading as ProviderUnavailable."""
+
+ def test_sdk_connection_error_name_match(self) -> None:
+ """openai.APIConnectionError has 'ConnectionError' in class name."""
+ exc = type("APIConnectionError", (Exception,), {})("cannot connect")
+ with pytest.raises(ProviderUnavailable):
+ classify_and_raise(exc, model=_model())
+
+ def test_sdk_timeout_name_match(self) -> None:
+ """anthropic.APITimeoutError has 'Timeout' in class name."""
+ exc = type("APITimeoutError", (Exception,), {})("timed out")
+ with pytest.raises(ProviderUnavailable):
+ classify_and_raise(exc, model=_model())