Skip to content

fix: throw after commit failure when any after commit callback fails - #50

Merged
lindyhopchris merged 1 commit into
fix/48-after-commit-unit-of-workfrom
fix/after-commit-failure
Nov 19, 2026
Merged

lindyhopchris merged 1 commit into
fix/48-after-commit-unit-of-workfrom
fix/after-commit-failure

Conversation

@lindyhopchris

Copy link
Copy Markdown
Member

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, UnitOfWorkManager rethrew that exception as-is. That made it impossible to tell apart from a unit of work that failed and did not commit.

  • UnitOfWorkManager now always throws AfterCommitCallbacksFailed when 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\AfterCommitFailure interface, which extends ApplicationException:

    • AfterCommitCallbacksFailed implements it.
    • Its exceptions(): non-empty-list<Throwable> method gives access to the underlying failures when catching the interface.
  • The UnitOfWorkManager contract documents the two outcomes:

    • @throws AfterCommitFailure when the unit of work committed but after commit work failed.
    • @throws Throwable for any failure before the commit.

    Keeping Throwable alongside AfterCommitFailure matters. Without it, phpstan would treat execute() as throwing only AfterCommitFailure, and report catches around it, such as the one in ExecuteInUnitOfWork, 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

  • Docs: the "Deferring Work" section now shows catching 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.
  • Changelog:
    • ### Added: the new interface.
    • ### Changed: a single failure is now wrapped.

Tests

  • Updated the single-failure and guard tests in UnitOfWorkManagerTest and FakeUnitOfWorkManagerTest to expect the wrapped exception. A shared assertSoleAfterCommitFailure() helper checks the type, the interface, the message, the single exception and the previous exception.
  • AfterCommitCallbacksFailedTest covers the interface and a single wrapped exception.

composer all passes locally, and the test suite also passes on PHP 8.4. array_first() comes from the existing symfony/polyfill-php85 dependency.

🤖 Generated with Claude Code

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>
@lindyhopchris
lindyhopchris added this pull request to stack #51 November 19, 2026 10:46
@lindyhopchris lindyhopchris self-assigned this Nov 19, 2026
@lindyhopchris
lindyhopchris merged commit 94fe3f5 into develop Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant