Repository navigation
fix: throw after commit failure when any after commit callback fails - #50
Merged
lindyhopchris merged 1 commit intoNov 19, 2026
Merged
Conversation
The unit of work manager now wraps every after commit callback failure in an AfterCommitCallbacksFailed exception, including when only one callback fails. Previously a single failure was rethrown as-is, so calling code could not tell it apart from a unit of work that failed and did not commit. The exception implements a new AfterCommitFailure interface, which exposes the underlying exceptions via exceptions(). The unit of work manager contract documents that execute() throws this interface when the unit of work committed but after commit work failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Note
Stacked on #49. Merge that first; this PR will then retarget
develop.Summary
Calling code needs to know whether a unit of work committed. Before this change, if exactly one after commit callback failed,
UnitOfWorkManagerrethrew that exception as-is. That made it impossible to tell apart from a unit of work that failed and did not commit.UnitOfWorkManagernow always throwsAfterCommitCallbacksFailedwhen any after commit callback fails, including when only one fails. The single-failure message is now singular:1 after commit callback failed.New
Contracts\Application\UnitOfWork\AfterCommitFailureinterface, which extendsApplicationException:AfterCommitCallbacksFailedimplements it.exceptions(): non-empty-list<Throwable>method gives access to the underlying failures when catching the interface.The
UnitOfWorkManagercontract documents the two outcomes:@throws AfterCommitFailurewhen the unit of work committed but after commit work failed.@throws Throwablefor any failure before the commit.Keeping
ThrowablealongsideAfterCommitFailurematters. Without it, phpstan would treatexecute()as throwing onlyAfterCommitFailure, and report catches around it, such as the one inExecuteInUnitOfWork, as dead code.This is treated as a non-breaking fix: calling code should always have been able to tell this scenario apart. The original exception is still available via
exceptions(), and as the previous exception.Docs and changelog
AfterCommitFailure. The "After Commit Queue" section explains that if a unit of work started from an after commit callback fails, that failure is reported as an after commit failure of the outer unit of work, which did commit.### Added: the new interface.### Changed: a single failure is now wrapped.Tests
UnitOfWorkManagerTestandFakeUnitOfWorkManagerTestto expect the wrapped exception. A sharedassertSoleAfterCommitFailure()helper checks the type, the interface, the message, the single exception and the previous exception.AfterCommitCallbacksFailedTestcovers the interface and a single wrapped exception.composer allpasses locally, and the test suite also passes on PHP 8.4.array_first()comes from the existingsymfony/polyfill-php85dependency.🤖 Generated with Claude Code