Skip to content

[Messenger] Add UnwrapHandlerExceptionMiddleware #52949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented Dec 8, 2023

Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #52300
License MIT

In competition with #52952

When using the HandleTrait, the HandlerFailedException just adds noise as the wrapped exception is the one we would expect to be thrown.

This PR adds an UnwrapHandlerExceptionMiddleware (idea stolen from Sulu’s UnpackExceptionMiddleware): added to a bus before the HandleMessageMiddleware, it will throw the single exception wrapped in a HandlerFailedException.

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "7.1 for features".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot added this to the 7.1 milestone Dec 8, 2023
@MatTheCat MatTheCat force-pushed the ticket_52300 branch 2 times, most recently from 7b50f67 to 7514be6 Compare December 8, 2023 16:46
@ro0NL
Copy link
Contributor

ro0NL commented Dec 8, 2023

When using the HandleTrait, the HandlerFailedException just adds noise

why not unwrap from within HandleTrait then?

edit: oh BC -.-, perhaps introduce a new property flag instead 🤔

@MatTheCat MatTheCat force-pushed the ticket_52300 branch 2 times, most recently from 3d72517 to 99e8e2b Compare December 8, 2023 17:01
@MatTheCat
Copy link
Contributor Author

MatTheCat commented Dec 8, 2023

perhaps introduce a new property flag instead

Will give it a try thanks! The property would only serve as a BC layer so I’m not sure if https://symfony.com/doc/current/contributing/code/bc.html#adding-an-argument-to-a-public-method would apply?

@ro0NL
Copy link
Contributor

ro0NL commented Dec 8, 2023

adding new private property to traits is allowed :)

it not sure why it would 'serve as a BC layer', it could be just a new feature

if we think it's the better default, then perhaps deprecating HandleTrait in favor of a new QueryBusTrait is the better way. It would solve ambigious naming, and we could mark the message bus property readonly right away.

I dont like the middleware approach, since it might force users to split their bus into multiple buses. IMHO it breaks the abstraction of $theBus->dispatch($aMessage), and comes with double middleware bookkeeping.

@MatTheCat
Copy link
Contributor Author

MatTheCat commented Dec 8, 2023

adding new private property to traits is allowed :)

Oh indeed I thought you were talking about a new argument for HandleTrait::handle.

it not sure why it would 'serve as a BC layer', it could be just a new feature

AFAIU we first need a way to make the new behavior opt-in (to keep BC), but then remove the old one. The opt-in mechanism would then only serve as a BC layer.

perhaps deprecating HandleTrait in favor of a new QueryBusTrait is the better way.

Don’t know about that, but QueryBus seems too specific: you could use the HandleTrait to implement a command bus e.g.
Something like SingleHandlingTrait maybe..?

@MatTheCat
Copy link
Contributor Author

@OskarStark @chalasr FYI I also opened #52952 which is an alternative proposed by @ro0NL I find better. Do you have a preference?

@MatTheCat
Copy link
Contributor Author

Closing, since there is no traction and a solution is trivial to implement in userland.

@MatTheCat MatTheCat closed this Feb 2, 2024
@MatTheCat MatTheCat deleted the ticket_52300 branch February 2, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Messenger] Make HandleTrait unwrap HandlerFailedException
5 participants