refactor(core): replace fragile string-based errors with a type-safe … - #114
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughIntroduces a typed error hierarchy and refactors providers (Anthropic, Google AI Studio, OpenAI) and CLI to throw and handle specific error classes (authentication, authorization, network, rate limit, invalid model, provider). Removes string-based parsing, adds provider-context messages, and preserves CLI exit behavior. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant CLI as CLI (index.ts)
participant Provider as Provider (Anthropic/Google/OpenAI)
participant API as Upstream API
User->>CLI: run command
CLI->>Provider: generate/stream request
Provider->>API: call
API-->>Provider: response or error
alt success
Provider-->>CLI: result
CLI-->>User: output
else error (typed)
Provider--x CLI: throw AuthenticationError / RateLimitError / NetworkError / InvalidModelError / ProviderError
CLI->>CLI: instanceof dispatch
CLI-->>User: print targeted guidance
CLI->>CLI: process.exit(1)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
e01393e to
b439750
Compare
b439750 to
1488bd5
Compare
…system
Pull Request
Description
This commit introduces a significant refactoring of the core error handling system to enhance stability and user experience. The previous implementation, which relied on fragile string-matching of error messages, has been replaced with a robust, type-safe architecture. A new hierarchy of custom error classes, including
AuthenticationError,NetworkError, andRateLimitError, has been established . AI providers have been updated to throw these specific error types, allowing the CLI's central error handler to reliably identify the root cause of a failure usinginstanceofchecks. This new approach makes the application resilient to changes in external API error messages and enables the delivery of clearer, more actionable feedback to the user, ultimately making the tool easier to debug and use.Type of Change
Related Issues
Changes Made
Created Custom Error Types: Introduced specific error classes like
AuthenticationErrorandNetworkErrorto replace unreliable error text checking.Updated AI Providers: Providers now identify issues and throw these new, specific error types.
Improved CLI Feedback: The command-line interface now catches these specific errors to give users clearer, more helpful advice.
AI Provider Impact
Component Impact
Testing
Test Environment
Performance Impact
Breaking Changes
Screenshots/Demo
Checklist
Additional Notes
Summary by CodeRabbit