fix: route cache-write failures through exception_handler#48
Open
waltzforvenus wants to merge 1 commit into
Open
fix: route cache-write failures through exception_handler#48waltzforvenus wants to merge 1 commit into
waltzforvenus wants to merge 1 commit into
Conversation
Previously exception_handler only protected the cache read (client.get). If Redis failed while storing the result on a cache miss, the exception propagated to the caller even when an exception_handler was configured. Wrap the cache-miss path so storage failures are handled the same way as lookup failures; without a handler the exception is re-raised as before. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
(sorry finally could be fucked to fix the formatting issues using claude, this is the version i use on prod) |
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.
Problem
exception_handlercurrently only protects the cache read:client.get(key)is wrapped in try/except, but on a cache miss the write path is not. If Redis becomes unavailable between the failedgetand the subsequent store (or the store itself fails — e.g. connection drop, OOM, cluster failover), the exception propagates to the caller even though anexception_handlerwas configured to make caching failures non-fatal.Fix
Wrap the cache-miss path (calling the original function, serializing the result, and the Lua cache-set script) in a try/except that delegates to
exception_handlerwhen one is configured, matching the existing behaviour of the read path. Without a handler, the exception is re-raised, so behaviour is unchanged for users who don't useexception_handler.The handler receives the same
(exception, original_fn, args, kwargs)signature as on the read path, so existing handlers (which typically fall back to calling the function directly) work unchanged.🤖 Generated with Claude Code