-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Improve error reporting when targetting the wrong Request class #54015
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
Comments
I figured out that |
Hi @nicolas-grekas I'm trying to tackle the issue and on the 7.1 branch when trying to reproduce, I'm getting this error right away:
that comes from Could you please post a full trace of the error so I could trace back why it's not happening the same way for me? |
I'm doing these steps to reproduce: symfony new test --webapp
cd test
symfony make:controller hello
# then add Symfony\Component\BrowserKit\Request as argument to HelloController::index() Going to |
@nicolas-grekas I reproduced it, thanks. Now the question regarding this part:
Problem is,
I personally prefer second way but I may lack context since it's my first contribution. |
You've go it right. The first way is basically what I describe in this PR so that's my preference. It improves things by providing a way for resolvers to give more accurate feedback in case an argument could not be found but a resolver "thought" it was still the one targeted. |
@nicolas-grekas Awesome! I will follow the first way then. Quick question - in a hypothetical case when multiple resolvers throw an exception, is there a preferred way how to combine them in a single one? |
Not exactly, maybe a list with an intro saying "Here are some possible hints:". We'll see :) |
@nicolas-grekas I've created a PR. The error will look like this: Let me know if you prefer another format 👍 |
…e wrong Request class (ilyachase) This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [HttpKernel] Improve error reporting when requiring the wrong Request class | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #54015 | License | MIT `FailedToResolveValueException` is introduced to be used inside any implementer of `ValueResolverInterface` to specify why exactly a value cannot be resolved. It's later used in `ArgumentResolver` to compute an exception if no value resolvers can resolve the value. Commits ------- 1cfc723 [HttpKernel] Improve error reporting when requiring the wrong Request class
When I create a controller action with a
Request $request
argument, the IDE will suggest me to useSymfony\Component\BrowserKit\Request
first. If I'm not careful and select this, I'll get an error saying this:That's not good enough. Instead, it'd be better to tell something like "did you mean to use Symfony\Component\HttpFoundation\Request instead?". The same could happen with any other "Request" class of course.
The current error message comes from
ServiceValueResolver
trying to access an errored "request" service. This looks wrong also since this prevents any other resolver (lower priority ones) from resolving the argument. The error I would expect instead is the one thrown by ArgumentResolver itself when the resolver chain is over:My proposal to fix both issues would be to introduce a special kind of exceptions that ArgumentResolver would use to compute its error message if no other resolver resolved the argument.
Then, we would make RequestValueResolver throw this exception when a type ends with
Request
but has the wrong namespace for example.WDYT?
Help wanted :)
The text was updated successfully, but these errors were encountered: