narrow bare except Exception in provider token status and model fetch#13
narrow bare except Exception in provider token status and model fetch#13HrachShah wants to merge 14 commits into
Conversation
…to specific types — WebSocket.send_text raises (RuntimeError, ConnectionResetError) when disconnected, get_metrics raises (RuntimeError, ValueError) for asyncio/data issues; catching all Exception masked these specific failures
…onseError — redis.xrange and xdel raise ResponseError on failures; catching all Exception masked this specific redis failure
… specific types — base64.b64decode raises (ValueError, TypeError) for invalid base64 input, AESGCM.decrypt raises ValueError when key is wrong or tag verification fails; catching all Exception masked these specific failures
…ponseError — redis.xadd raises ResponseError for stream errors, and falling back to in-memory on that specific failure is more targeted than masking all exceptions
…er_info catches (OSError, KeyError, TypeError, IndexError) from dict/getattr access on the Supabase response, and the idempotency cache handler catches (ValueError, TypeError) from json.loads; catching all Exception masked these specific failures
…fic types — xreadgroup/xpending/xclaim raise ResponseError, OutcomeRecord.from_stream raises (ValueError, TypeError), xack operates on Redis int response — catching all Exception masked these specific failures
…SON decode errors — xack returns an integer count, so only Redis-level failures apply
…fic types — publish/rollback/snapshot/delete/subscribe use Redis ops (ResponseError), load_current and history use (json.JSONDecodeError, ResponseError), and callback uses (json.JSONDecodeError, ValueError, TypeError) — catching all Exception masked these specific failures
…rror, TypeError, ValueError) — eval raises SyntaxError for malformed expressions, NameError for undefined variables, TypeError for type mismatches, and ValueError for invalid operations; catching all Exception masked these specific evaluation failures
…aml.YAMLError, ValueError) — open raises OSError for file I/O failures, yaml.safe_load raises YAMLError for malformed YAML, and model_validate raises ValueError for invalid schema; catching all Exception masked these specific file and parsing failures
…ogger — model_validate_json raises (ValueError, TypeError), LSH query raises (TypeError, ValueError, KeyError), execute_hedged catches (ProviderError, ValueError, TypeError), Supabase execute raises (OSError, ValueError, TypeError); catching all Exception masked these specific failures
…se import raises ImportError, request.body() raises OSError, model_validate_json raises (ValueError, TypeError); catching all Exception masked these specific failures
… key lookup and rate limit checks catch redis.asyncio.RedisError, idempotency check and store catch RedisError, httpx request cancellation catches (OSError, httpx.RequestError)
…etch get_codex_token_status tries to decode the ChatGPT OAuth JWT to surface expiry and plan_type, then falls back to "Token found (unable to decode JWT)" if anything goes wrong. The body only does operations on a string JWT: token.split
Reviewer's GuideNarrows previously broad Flow diagram for Redis idempotency check with narrowed RedisError handlingflowchart TD
A[check request_id] --> B{_redis is not None?}
B -- no --> C[_check_memory]
B -- yes --> D[_check_redis]
D --> E{redis.asyncio.RedisError?}
E -- yes --> F[log 'Redis idempotency check failed' and _check_memory]
E -- no --> G[return Redis result]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
More reviews will be available in 54 minutes and 8 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
✨ 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 |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the Redis-backed components (e.g. policy_publisher, outcome_consumer, audit), consider catching the broader redis.asyncio.RedisError rather than only ResponseError so connection/timeouts and other operational Redis failures are still handled by these error paths.
- In providers/opencode.fetch_opencode_models, the three separate except blocks that all just
passcan be combined into a singleexcept (httpx.RequestError, ValueError, TypeError, AttributeError):for clarity, and you may want to add minimal logging there to make silent failures easier to diagnose.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the Redis-backed components (e.g. policy_publisher, outcome_consumer, audit), consider catching the broader redis.asyncio.RedisError rather than only ResponseError so connection/timeouts and other operational Redis failures are still handled by these error paths.
- In providers/opencode.fetch_opencode_models, the three separate except blocks that all just `pass` can be combined into a single `except (httpx.RequestError, ValueError, TypeError, AttributeError):` for clarity, and you may want to add minimal logging there to make silent failures easier to diagnose.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary
Narrows the bare
except Exceptionblocks in two FreeRelay provider modules to the specific exception types their inner operations raise.Changes
freerelay/providers/codex.py—get_codex_token_statusThe function tries to decode the ChatGPT OAuth JWT to surface
Summary by Sourcery
Tighten exception handling across Redis, HTTP, parsing, cryptography, routing, and middleware paths to avoid masking unexpected errors while preserving existing fallbacks and logging behavior.
Enhancements:
except Exceptionclauses with specific Redis, HTTPX, JSON/parsing, and cryptography-related exception types throughout control-plane learners, data-plane ingress, and shared services.