refactor(llm): chain exceptions in client error handlers (ruff B904)#145
Merged
CGFixIT merged 1 commit intoJun 21, 2026
Merged
Conversation
LocalLLMClient.generate and GrokClient.generate re-raise LLMServiceError / GrokServiceError from inside their except blocks without 'from', discarding the original exception context. The project's own ruff config selects the 'B' rules, so these are six B904 (raise-without-from-inside-except) violations. Add 'from e' to all six handlers (and bind the two TimeoutException blocks with 'as e') so the underlying httpx error is preserved as __cause__. This keeps the real network/HTTP failure visible in tracebacks and audit diagnostics instead of masking it behind a generic wrapper. Exception types, messages, and details are unchanged, so callers that catch these errors are unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LvLWMML8cpBq2q81kL1ByJ
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
LocalLLMClient.generateandGrokClient.generatere-raiseLLMServiceError/GrokServiceErrorfrom inside theirexceptblocks withoutfrom, discarding the original exception's context (__cause__). The project's ownruffconfig selects theBrule family (pyproject.toml→[tool.ruff.lint] select = [..., "B", ...]), so these are sixB904(raise-without-from-inside-except) violations.Why it matters
The wrappers flatten every failure into a generic message. When something goes wrong talking to LM Studio or xAI (TLS error, connection reset, malformed JSON), the underlying
httpxexception — the part that actually tells you what broke — is thrown away. Chaining preserves it as__cause__, so the real cause shows up in tracebacks and debugging:The change
Add
from eto all six handlers and bind the twoTimeoutExceptionblocks withas e. Behaviour-preserving: exception types, messages, anddetailsare unchanged, so any caller catchingLLMServiceError/GrokServiceErroris unaffected — only__cause__is now populated.Verification
🤖 Generated with Claude Code
https://claude.ai/code/session_01LvLWMML8cpBq2q81kL1ByJ
Generated by Claude Code