Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Improve error reporting in router panel of web profiler#17744
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
xabbuh commentedFeb 9, 2016
Tests are falling now. Status: Needs work |
javiereguiluz commentedFeb 10, 2016
I've fixed tests and I've added a test for the new error message. |
OskarStark commentedFeb 17, 2016
LGTM |
yceruto commentedFeb 24, 2016
@javiereguiluz I've investigated this problem too and I found a way to display the traces instead of display an exception message: +use Symfony\Component\HttpFoundation\Request;class TraceableUrlMatcher extends UrlMatcher{ //...+ public function getTracesRequest(Request $request)+ {+ $this->request = $request;++ $ret = $this->getTraces($request->getPathInfo());++ $this->request = null;++ return $ret;+ }} And use Symfony\Component\HttpFoundation\Request;class RouterController{ //... public function panelAction($token) { //...+ /** @var RequestDataCollector $request */ $request = $profile->getCollector('request');+ $traceRequest = Request::create(+ $request->getPathInfo(),+ $request->getRequestServer()->get('REQUEST_METHOD'),+ $request->getRequestAttributes()->all(),+ $request->getRequestCookies()->all(),+ [],+ $request->getRequestServer()->all()+ ); return new Response($this->twig->render('@WebProfiler/Router/panel.html.twig', array( 'request' => $request, 'router' => $profile->getCollector('router'),- 'traces' => $matcher->getTraces($request->getPathInfo()),+ 'traces' => $matcher->getTracesRequest($traceRequest), )), 200, array('Content-Type' => 'text/html')); }}WDYT? |
javiereguiluz commentedFeb 29, 2016
| $matchingRequest = Request::create('/foo','GET',array(),array(),array(),array('HTTP_USER_AGENT' =>'Firefox')); | ||
| $traces =$matcher->getTracesFromRequest($matchingRequest); | ||
| $this->assertEquals("Route matches!",$traces[0]['log']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fabbot suggest to use single quote here.
yceruto commentedFeb 29, 2016
AppVeyor build faild (no related) |
| return$this->traces; | ||
| } | ||
| publicfunctiongetTracesFromRequest(Request$request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
getTraces*For*Request I think this is the pattern we are using elsewhere.
fabpot commentedFeb 29, 2016
LGTM |
fabpot commentedMar 3, 2016
Thank you@javiereguiluz. |
…aviereguiluz)This PR was squashed before being merged into the 2.7 branch (closes#17744).Discussion----------Improve error reporting in router panel of web profiler| Q | A| ------------- | ---| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#17342| License | MIT| Doc PR | -### ProblemIf you define a route condition like this:```yamlapp: resource: '@AppBundle/Controller/' type: annotation condition: "request.server.get('HTTP_HOST') matches '/.*\.dev/'"```When browsing the Routing panel in the web profiler, you see an exception:#### Why?Because the route condition uses the `request` object, but the special `TraceableUrlMatcher` class doesn't get access to the real `request` object but to the special object obtained via:```php$request = $profile->getCollector('request');```These are the contents of this pseudo-request:`request.server.get(...)` condition fails because `request.server` is `null`. The full exception message shows this:### SolutionI propose to catch all exceptions in `TraceableUrlMatcher` and display an error message with some details of the exception:Commits-------1001554 Improve error reporting in router panel of web profiler
stof commentedMar 3, 2016
@javiereguiluz not passing a Request object when evaluating the condition should be considered as a bug IMO. Assuming that the collector has a compatible-enough API is not fine. |
stof commentedMar 3, 2016
sorry, just saw that it was indeed done properly in the final diff. I commented too fast |
peshi commentedMar 27, 2016
Attempted to load class "Request" from namespace "Symfony\Bundle\WebProfilerBundle\Controller". In vendor/symfony/symfony/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php Missing "use" statement? |
xabbuh commentedMar 29, 2016
…iler (javiereguiluz)This PR was squashed before being merged into the 2.7 branch (closessymfony#17744).Discussion----------Improve error reporting in router panel of web profiler| Q | A| ------------- | ---| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |symfony#17342| License | MIT| Doc PR | -### ProblemIf you define a route condition like this:```yamlapp: resource: '@AppBundle/Controller/' type: annotation condition: "request.server.get('HTTP_HOST') matches '/.*\.dev/'"```When browsing the Routing panel in the web profiler, you see an exception:#### Why?Because the route condition uses the `request` object, but the special `TraceableUrlMatcher` class doesn't get access to the real `request` object but to the special object obtained via:```php$request = $profile->getCollector('request');```These are the contents of this pseudo-request:`request.server.get(...)` condition fails because `request.server` is `null`. The full exception message shows this:### SolutionI propose to catch all exceptions in `TraceableUrlMatcher` and display an error message with some details of the exception:Commits-------1001554 Improve error reporting in router panel of web profiler

Problem
If you define a route condition like this:
When browsing the Routing panel in the web profiler, you see an exception:
Why?
Because the route condition uses the
requestobject, but the specialTraceableUrlMatcherclass doesn't get access to the realrequestobject but to the special object obtained via:These are the contents of this pseudo-request:
request.server.get(...)condition fails becauserequest.serverisnull. The full exception message shows this:Solution
I propose to catch all exceptions in
TraceableUrlMatcherand display an error message with some details of the exception: