-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tests are falling now. Status: Needs work |
I've fixed tests and I've added a test for the new error message. |
LGTM |
@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? |
|
||
$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.
AppVeyor build faild (no related) |
@@ -40,6 +41,15 @@ public function getTraces($pathinfo) | |||
return $this->traces; | |||
} | |||
|
|||
public function getTracesFromRequest(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.
LGTM |
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 | - ### Problem If you define a route condition like this: ```yaml app: 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:  ### Solution I 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
@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. |
sorry, just saw that it was indeed done properly in the final diff. I commented too fast |
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? |
…iler (javiereguiluz) This PR was squashed before being merged into the 2.7 branch (closes symfony#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 | - ### Problem If you define a route condition like this: ```yaml app: 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:  ### Solution I 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
request
object, but the specialTraceableUrlMatcher
class doesn't get access to the realrequest
object but to the special object obtained via:These are the contents of this pseudo-request:
request.server.get(...)
condition fails becauserequest.server
isnull
. The full exception message shows this:Solution
I propose to catch all exceptions in
TraceableUrlMatcher
and display an error message with some details of the exception: