-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Prefer BadRequestException over native exception in ParameterBag #51196
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
Conversation
there is a big difference here. RequestExceptionInterface has a very specific behavior. Those exceptions will be turned into specific 4xx status code for the response instead of being reported as bugs in the code. So -1 for that. |
However, the InputBag should override the new methods to throw a BadRequestException when there is an unexpected input value, as done for other methods (see |
Isn't the ParameterBag coming from the request too ?
Could it be still possible to throw a Symfony-scoped exception rather than the native one ?
|
@VincentLanglet ParameterBag is used directly (instead of a specialized child class) only for |
If so, the SessionNotFound shouldn't implement I don't see a reason for a different behavior for SessionNotFound and for wrong data in ParameterBag then. But I'm less concern about which exceptions/interface used. My main goal would be to scope the exception thrown, would you be ok with this @stof ? Then we'll have to decide
|
There is some indirection but that's the case, all is fine in InputBag to me.
Looks like you might be right. Unless someone has an argument to keep the interface (other than BC I mean?)
What's your motivation for this goal? Any real-world use case that requires such discrimination for ParameterBag? |
Isn't the BC argument a blocking point ?
Kinda the same than #49881 It could be usful to do
But my main usage for scoped SymfonyException are the PHPStan analysis. This setup enforce developer to try/catch all the exception thrown (except the excluded exception). For instance a general config would be to exclude LogicException, some other exceptions and ask to catch all other RuntimeException.
which allow to write
without the need to catch the exception. An example can be found here, in the own config file of the phpstan-src repository: When they are not scoped, doing
will exclude far more exception than wanted. |
Then we should consider adding UnexpectedValueException to HttpFoundation instead. @stof WDYT? |
Closing so keep the discussion relevant to the original PR. Please follow up in a new PR. |
…ected values (VincentLanglet) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [HttpFoundation] Use Symfony exception for request unexpected values | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Instead of #51196 Cf #51196 (comment) cc `@nicolas`-grekas Commits ------- 72e374d [HttpFoundation] Use Symfony exception for request unexpected values
In the #48525 PR,
\UnexpectedValueException
were used instead ofBadRequestException
which\UnexpectedValueException
RequestExceptionInterface
Symfony should prefer as possible to use scoped exception, AND the InputBag is already throwing only
BadRequestException
so the ParameterBag should be consistent with this IMHO.