Add HandlerFailedException to CommandBus::dispatch @throws#874
Conversation
Without declaring it, catching the exception forces `@phpstan-ignore catch.neverThrown` everywhere, which is a bad pattern. Signed-off-by: Nicolo Singer <nicolo@whatwedo.ch>
|
This is the wrong place, since this interface has no knowledge of the bundle's Symfony implementation. In the library's minimal implementation, we're already throwing different exceptions: So this should most likely be handled in the bundle instead: One thing to keep in mind is that we're already unwrapping the Not sure though, if it would resolve the phpstan issue. You could try it out in your local checkout. |
|
@DanielBadura anyway, all of this would still not fix the phpstan Error. Could we add a generic |
|
Most probably we could but first I would like to check why it does not occur before 🤔 . Are you injecting our I just tried in a project of mine, catching an public function __construct(
private readonly CommandBus $commandBus,
) {
}
public function __invoke(Request $request, string $id): Response
{
try {
$this->commandBus->dispatch(new Command(...));
} catch (HandlerFailedException $e) {
// do something
}
// ...
}Regarding the not unpacking: Yeah, it seems it was changed from index based to an hashmap? Need to check that and fix it. Using array_first is only possible in 8.5, so most probably using array_values()[0] it is. |
|
@DanielBadura I am using |

Without declaring it, catching the exception forces
@phpstan-ignore catch.neverThrowneverywhere, which is a bad pattern.