feat: typed error hierarchy for HTTP status codes#19
Merged
jackparnell merged 1 commit intomainfrom Apr 9, 2026
Merged
Conversation
Adds specific exception subclasses so callers can react to failure modes without inspecting status codes. All subclass ColonyAPIError so existing `except ColonyAPIError` code keeps working unchanged. ColonyAuthError — 401, 403 (invalid key / forbidden) ColonyNotFoundError — 404 ColonyConflictError — 409 (already voted, name taken, etc.) ColonyValidationError — 400, 422 (bad payload) ColonyRateLimitError — 429 (with .retry_after attribute) ColonyServerError — 5xx ColonyNetworkError — DNS / connection / timeout (status=0) Why: downstream packages (langchain-colony, crewai-colony) currently string-match HTTP codes to format hints and decide whether to retry. That logic belongs in the SDK, not in every consumer. With this change, crewai-colony's _STATUS_HINTS table can be deleted and replaced with `except ColonyRateLimitError` etc. Other changes: - Status hints in error messages: "not found — the resource doesn't exist or has been deleted", "rate limited — slow down...", etc. - ColonyRateLimitError exposes `.retry_after` parsed from the Retry-After header so callers can implement higher-level backoff on top of the SDK's built-in retries. - Sync URLError and async httpx.HTTPError both wrap as ColonyNetworkError with status=0. - _build_api_error dispatches to the right subclass via _error_class_for_status, shared by sync + async + register paths. Tests: 13 sync + 7 async tests for the typed hierarchy. Coverage stays at 100% (448 / 448 statements). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ColonistOne
added a commit
that referenced
this pull request
Apr 9, 2026
Two changes that ship together so v1.5.0 can be the first release cut
via the new automation:
1. Release workflow at .github/workflows/release.yml — triggered on
`v*` tag push. Stages:
- test: runs ruff, mypy, pytest before anything else
- build: builds wheel + sdist, refuses to proceed if
the tag version doesn't match pyproject.toml
- publish: uploads to PyPI via OIDC trusted publishing
(no API token stored anywhere — short-lived
token minted by PyPI from the GitHub Actions
OIDC identity at publish time)
- github-release: extracts the matching CHANGELOG section and
creates a GitHub Release with the wheel + sdist
attached
2. Version bump 1.4.0 → 1.5.0 in pyproject.toml and __init__.py.
3. CHANGELOG: consolidated the 1.5.0 section into a clean, ordered
summary covering everything that's landed since 1.4.0:
- AsyncColonyClient (PR #18)
- Typed error hierarchy (PR #19)
- RetryConfig + 5xx default retry (PR #20)
- py.typed + verify_webhook + Dependabot (PR #21)
- Pagination iterators (PR #23)
- Coverage + Codecov (PR #17)
- This release automation
Coverage at 100% (514/514 statements). 215 tests passing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6 tasks
ColonistOne
added a commit
that referenced
this pull request
Apr 9, 2026
Two changes that ship together so v1.5.0 can be the first release cut
via the new automation:
1. Release workflow at .github/workflows/release.yml — triggered on
`v*` tag push. Stages:
- test: runs ruff, mypy, pytest before anything else
- build: builds wheel + sdist, refuses to proceed if
the tag version doesn't match pyproject.toml
- publish: uploads to PyPI via OIDC trusted publishing
(no API token stored anywhere — short-lived
token minted by PyPI from the GitHub Actions
OIDC identity at publish time)
- github-release: extracts the matching CHANGELOG section and
creates a GitHub Release with the wheel + sdist
attached
2. Version bump 1.4.0 → 1.5.0 in pyproject.toml and __init__.py.
3. CHANGELOG: consolidated the 1.5.0 section into a clean, ordered
summary covering everything that's landed since 1.4.0:
- AsyncColonyClient (PR #18)
- Typed error hierarchy (PR #19)
- RetryConfig + 5xx default retry (PR #20)
- py.typed + verify_webhook + Dependabot (PR #21)
- Pagination iterators (PR #23)
- Coverage + Codecov (PR #17)
- This release automation
Coverage at 100% (514/514 statements). 215 tests passing.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds specific exception subclasses so callers can react to failure modes without inspecting status codes. All subclass
ColonyAPIErrorso existingexcept ColonyAPIErrorcode keeps working unchanged — fully backward compatible.ColonyAuthErrorColonyNotFoundErrorColonyConflictErrorColonyValidationErrorColonyRateLimitError.retry_afterColonyServerErrorColonyNetworkErrorWhy
Downstream packages (
langchain-colony,crewai-colony) currently string-match HTTP codes to format hints and decide whether to retry. That logic belongs in the SDK, not in every consumer. With this change,crewai-colony's_STATUS_HINTStable can be deleted and replaced withexcept ColonyRateLimitErroretc.Other changes
"not found — the resource doesn't exist or has been deleted","rate limited — slow down and retry after the backoff window", etc. So logs and LLMs don't need to consult docs.ColonyRateLimitError.retry_after— parsed from theRetry-Afterheader. Callers can implement higher-level backoff on top of the SDK's built-in retries.URLErrorand asynchttpx.HTTPErrorboth wrap asColonyNetworkError(status=0)._build_api_errordispatches via_error_class_for_status, shared by sync + async + register paths.Example
Test plan
TestTypedErrors) covering each status → subclass mapping,retry_afterpropagation, network error wrapping, and the unknown-status fallback to baseColonyAPIErrortests/test_async_client.py::TestErrorspytest --covreports 100% (448/448 statements)ruff check/ruff format --check/mypy src/all cleanFollow-up (next PRs, not this one)
Once released,
crewai-colonyandlangchain-colonycan:_STATUS_HINTStables and rely on the SDK's status hintsif e.status == 429blocks withexcept ColonyRateLimitErrorColonyRateLimitError.retry_afterfor higher-level backoff coordination