Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
javiereguiluz wants to merge9 commits intosymfony:2.7fromjaviereguiluz:fix_17342

Conversation

@javiereguiluz
Copy link
Member

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#17342
LicenseMIT
Doc PR-

Problem

If you define a route condition like this:

app:resource:'@AppBundle/Controller/'type:annotationcondition:"request.server.get('HTTP_HOST') matches '/.*\.dev/'"

When browsing the Routing panel in the web profiler, you see an exception:

problem

Why?

Because the route condition uses therequest object, but the specialTraceableUrlMatcher class doesn't get access to the realrequest object but to the special object obtained via:

$request =$profile->getCollector('request');

These are the contents of this pseudo-request:

cause

request.server.get(...) condition fails becauserequest.server isnull. The full exception message shows this:

exception

Solution

I propose to catch all exceptions inTraceableUrlMatcher and display an error message with some details of the exception:

error_message

@xabbuh
Copy link
Member

Tests are falling now.

Status: Needs work

@javiereguiluz
Copy link
MemberAuthor

I've fixed tests and I've added a test for the new error message.

@OskarStark
Copy link
Contributor

LGTM

@yceruto
Copy link
Member

@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
Copy link
MemberAuthor

I've made the changes suggested by@yceruto. Everything works as expected and his solution is much better than mine. Now you can see better error messages when a route with an expression doesn't match:

not_match

Thanks@yceruto!


$matchingRequest = Request::create('/foo','GET',array(),array(),array(),array('HTTP_USER_AGENT' =>'Firefox'));
$traces =$matcher->getTracesFromRequest($matchingRequest);
$this->assertEquals("Route matches!",$traces[0]['log']);
Copy link
Member

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
Copy link
Member

AppVeyor build faild (no related)

return$this->traces;
}

publicfunctiongetTracesFromRequest(Request$request)
Copy link
Member

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
Copy link
Member

LGTM

@fabpot
Copy link
Member

Thank you@javiereguiluz.

fabpot added a commit that referenced this pull requestMar 3, 2016
…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:![problem](https://cloud.githubusercontent.com/assets/73419/12930027/553eeb08-cf76-11e5-90b1-ab0de6175d4e.png)#### 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:![cause](https://cloud.githubusercontent.com/assets/73419/12930052/804ea248-cf76-11e5-9c38-2e43e1654065.png)`request.server.get(...)` condition fails because `request.server` is `null`. The full exception message shows this:![exception](https://cloud.githubusercontent.com/assets/73419/12930079/9c7d6058-cf76-11e5-8eeb-45f5059c824c.png)### SolutionI propose to catch all exceptions in `TraceableUrlMatcher` and display an error message with some details of the exception:![error_message](https://cloud.githubusercontent.com/assets/73419/12930106/b29e31d2-cf76-11e5-868c-98d8b0cc4e5b.png)Commits-------1001554 Improve error reporting in router panel of web profiler
@fabpotfabpot closed thisMar 3, 2016
@stof
Copy link
Member

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
Copy link
Member

stof commentedMar 3, 2016

sorry, just saw that it was indeed done properly in the final diff. I commented too fast

@fabpotfabpot mentioned this pull requestMar 25, 2016
This was referencedMar 27, 2016
@peshi
Copy link

@javiereguiluz

Attempted to load class "Request" from namespace "Symfony\Bundle\WebProfilerBundle\Controller".

In vendor/symfony/symfony/src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php
Line 86. $traceRequest = Request::create(

Missing "use" statement?

@xabbuh
Copy link
Member

@peshi fixed in#18340

@fabpotfabpot mentioned this pull requestMar 30, 2016
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull requestMar 25, 2018
…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:![problem](https://cloud.githubusercontent.com/assets/73419/12930027/553eeb08-cf76-11e5-90b1-ab0de6175d4e.png)#### 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:![cause](https://cloud.githubusercontent.com/assets/73419/12930052/804ea248-cf76-11e5-9c38-2e43e1654065.png)`request.server.get(...)` condition fails because `request.server` is `null`. The full exception message shows this:![exception](https://cloud.githubusercontent.com/assets/73419/12930079/9c7d6058-cf76-11e5-8eeb-45f5059c824c.png)### SolutionI propose to catch all exceptions in `TraceableUrlMatcher` and display an error message with some details of the exception:![error_message](https://cloud.githubusercontent.com/assets/73419/12930106/b29e31d2-cf76-11e5-868c-98d8b0cc4e5b.png)Commits-------1001554 Improve error reporting in router panel of web profiler
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@javiereguiluz@xabbuh@OskarStark@yceruto@fabpot@stof@peshi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp