refactor(provider): collapse transport to a single deep complete()#23
Conversation
…ning API - Replace `get_commit_message` with `complete(system, user, model, max_tokens, temperature)` that owns the Anthropic client and collapses SDK exceptions into single `ProviderError` carrying `ErrorKind` (auth / rate-limit / connection / status) - Move four-branch `except anthropic.*` ladder into `complete()`; commands no longer import `anthropic` (APIError catch-all keeps the SDK surface from leaking past the seam) - Extract pure `_build_user_content()` helper in `suggest.py` for unit testing without mocks - Each command keeps its own `*_WORDING` dict per `ErrorKind` behind import-time exhaustiveness assertions - `test` calls `complete()` directly for generic completions, not the commit-message function - Update tests to mock `complete()` and `ProviderError` instead of anthropic exceptions Closes #21, closes #22. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Replaces the misnamed
provider.get_commit_messagewith a deepcomplete(system, user, model, max_tokens, temperature)transport shared by both commands, and folds the error-taxonomy work into the same seam. Outcome of an architecture-review grilling session on candidates #21 and #22 — which turned out to be the same seam, so they land together.What changed
provider.py—complete()owns the Anthropic client, key injection, and response unwrapping, and collapses the entireanthropicexception hierarchy into a singleProviderErrorcarrying anErrorKind(auth/rate_limit/connection/status). Ananthropic.APIErrorcatch-all ensures the SDK's error surface never leaks past the seam.commands/suggest.py— commit-prompt assembly extracted to a pure, private_build_user_contenthelper (single caller → kept private, not a module). Catches oneProviderError; wording lives in a per-commandSUGGEST_WORDINGmap.commands/test.py— callscomplete()directly instead of smuggling a joke through a commit-message-named function. Its ownTEST_WORDINGmap.assert set(MAP) == set(ErrorKind)).anthropicanymore — it's confined toprovider.py.Why
get_commit_messagewas ~90% transport with 9 lines of commit-specific assembly bolted on; thetestcommand proved the name lied by passing a joke as the "diff". The four-branchexcept anthropic.*ladder was also duplicated verbatim across both commands. One deep transport gives locality (error mapping in one place, mirroring the existingKeyStoreErrorprecedent) and leverage (callers shed theanthropicimport).Testing
get_commit_messagetests deleted (superseded bycompleteinterface tests); new tests assert each anthropic error maps to the correctErrorKind, and_build_user_contentis now unit-tested with zero mocks.Closes #21
Closes #22
🤖 Generated with Claude Code