fix: contain exceptions thrown by consumer onError callback - #13
Merged
Conversation
fail() runs as the terminal .catch of the serialized mount/reset chain. A consumer onError that threw would reject chainRef.current, producing an unhandled promise rejection and poisoning the chain so every subsequent mount/reset link was silently skipped — violating the documented invariant that a rejection never poisons the chain. Wrap the onError call in try/catch and route a callback exception to console.error so the diagnostic path can never become a new failure. Closes #9
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Fixes #9 — a consumer
onErrorcallback that throws escapes the wrapper as an unhandled promise rejection.fail()invokes the consumer'sonErrorunguarded. Sincefailis used as the terminal.catchhandler of the serialized mount/reset chain, a throw insideonErrorrejectschainRef.currentwith no downstream handler → unhandled promise rejection.It also has a consequence the original report didn't note: it poisons the serialized chain, violating the invariant the code documents (
// Every link ends in .catch so a rejection never poisons it.). OncechainRefis left rejected, subsequent mount/reset.thenlinks are silently skipped — later image changes are dropped and the consumer may be re-notified with a stale error.Fix
Wrap the
onErrorcall intry/catchand route a callback exception toconsole.error, so the diagnostic path can never become a new failure. The original error still reaches the consumer; callback exceptions can't escape.Severity note
This only triggers when the consumer's own
onErrorthrows (a misbehaving void callback), so it does not affect well-behaved callers. The fix is included because it is nearly free and makes the code's documented no-poison invariant actually hold.Test plan
npm test— 41 passing, including a new regression test ('contains a throwing onError without poisoning the chain') that asserts the throw is swallowed and the chain still resets afterward. Verified the test fails (unhandled rejection) with the guard removed.