Add error handling for Claude Code quota API failures#251
Conversation
When fetchClaudeCodeOAuthToken or fetchAnthropicUsage fails, the error was silently swallowed and users only saw "🚦 -" with no indication of what went wrong. Now errors are cached in the daemon, propagated via the CCInfoResponse, and displayed as short messages like "🚦 err:oauth" or "🚦 err:api:403" in the statusline. Closes #250 https://claude.ai/code/session_01H6KrQwMmpvN87z7mMsF57u
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the user experience by implementing robust error handling for Claude Code quota API failures. Instead of displaying a blank or missing indicator, users will now see a descriptive, color-coded error message in the statusline when the quota API encounters issues. This change provides immediate and actionable feedback, improving transparency and helping users understand why quota information might not be available. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively adds error handling for the Claude Code quota API. The changes are well-structured, propagating the error information from the daemon up to the statusline display. The inclusion of new fields in the data structures (ccStatuslineResult, CCInfoResponse, etc.) is consistent, and the logic to display errors only when data is unavailable is sound. The test coverage for the new error handling scenarios is also comprehensive.
I have one suggestion in daemon/cc_info_timer.go to improve the robustness of error parsing. Overall, this is a solid implementation.
| if len(msg) >= 6 && msg[:6] == "failed" { | ||
| return "api:decode" | ||
| } |
There was a problem hiding this comment.
While parsing error strings works, it can be brittle if the error message format changes. Using strings.HasPrefix is more idiomatic and slightly more robust than checking the length and slicing. Making the prefix check more specific also reduces the chance of false positives.
For a more robust long-term solution, consider introducing typed errors. This would allow you to use errors.As for type-safe error checking, avoiding string parsing altogether.
You will need to add import "strings" at the top of the file for the suggestion to work.
| if len(msg) >= 6 && msg[:6] == "failed" { | |
| return "api:decode" | |
| } | |
| if strings.HasPrefix(msg, "failed to decode") { | |
| return "api:decode" | |
| } |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 lastError not cleared in stopTimer, causing stale error display after inactivity restart
The stopTimer() method at daemon/cc_info_timer.go:150-154 clears usage, fetchedAt, and lastAttemptAt from the rate limit cache, but does not clear the newly added lastError field. After the timer stops due to inactivity and a new client triggers a restart, GetCachedRateLimit() returns nil (usage was cleared) while GetCachedRateLimitError() returns a stale error string from the previous session. This causes handleCCInfo at daemon/socket.go:257-258 to surface a stale error in the statusline, even though the previous error may no longer be relevant.
(Refers to lines 150-154)
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
This PR adds error tracking and display for Claude Code quota/rate limit API failures. When the quota API fails to fetch data, users now see a descriptive error message in the statusline instead of a blank indicator.
Key Changes
lastErrorfield toanthropicRateLimitCacheto store shortened error descriptionsshortenAPIError()function that converts API errors into concise statusline-friendly strings:api:XXX(e.g.,api:403)api:decodenetworkoauthfetchRateLimit()to capture and cache errors when OAuth token fetch or API calls failformatQuotaPart()to accept and display error messages in red when quota data is unavailableCCInfoResponseto includeQuotaErrorfield for communicating errors to clientsImplementation Details
nil; successful data fetches clear the error statehttps://claude.ai/code/session_01H6KrQwMmpvN87z7mMsF57u