Catching errors when using Bus::batch
inside of Bus::chain
on Sync Queue
#55077
Labels
Bus::batch
inside of Bus::chain
on Sync Queue
#55077
Laravel Version
11.44.2
PHP Version
8.2.27
Database Driver & Version
No response
Description
When using
Bus::chain(...)->catch(...)
, the catch callback will be transferred to aBus::batch
inside of the chain. This will result in the same callback to be executed twice, once for the batch and then for the chain. I do not understand why this should happen. The chain and the batch both have providable catch callbacks, so why would a batch receive all of the chain callbacks on top?Just for the sake of hopefully understanding it better:
When the Bus::batch is dispatched onto the queue, it will keep its catch callback outputting "batch callback", but it will also receive the catch callback outputting "chain callback". So if
MyJob
fails, the batch will output both "batch callback" AND "chain callback". Then the error will bubble up, which will cause the chain to run its catch callback, too, which will output "chain callback" again. Therefore: The chain callback has been called twice.Another thing.
On the sync queue (like in PHPUnit tests), the catch callback of Bus::batch is run in a transaction, which will even reverse any database changes done in the catch callback. That means I have to add checks inside of the catch callback since it's called twice, but I cannot test those check because my phpunit runs through the sync queue, which will revert any database changes in the first callback.
For reference:
Steps To Reproduce
For reference:
The text was updated successfully, but these errors were encountered: