8000 Improve error reporting in router panel of web profiler by javiereguiluz · Pull Request #17744 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed tests and added a new test
  • Loading branch information
javiereguiluz committed Feb 10, 2016
commit 098d3000cc0283d80e4a38b91bbfa4a85b64e612
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{% if trace.level == -1 %}
<tr class="status-error">
<td colspan="3">
{{ trace.name }}
{{ trace.log }}
</td>
</tr>
{% else %}
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Routing\Matcher;

use Symfony\Component\Routing\Exception\ExceptionInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

Expand All @@ -33,11 +34,12 @@ public function getTraces($pathinfo)

try {
$this->match($pathinfo);
} catch (ExceptionInterface $e) {
} catch (\Exception $e) {
$this->traces = array(array(
'name' => sprintf('[ERROR] The following exception prevented the route to be matched against application routes: "%s" (in %s line %d)', $e->getMessage(), $e->getFile(), $e->getLine()),
'log' => '-',
'level' => -1,
'log' => sprintf('[ERROR] The following exception prevented the route to be matched against application routes: "%s" (in %s line %d)', $e->getMessage(), $e->getFile(), $e->getLine()),
'name' => '-',
'path' => '-',
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,19 @@ public function getLevels($traces)

return $levels;
}

public function testExceptionOnRouteCondition()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), 'baz', array(), array(), "request.headers.get('User-Agent') matches '/firefox/i'"));

$context = new RequestContext();
$context->setHost('baz');

$matcher = new TraceableUrlMatcher($coll, $context);
$traces = $matcher->getTraces('/foo');

$this->assertEquals(-1, $traces[0]['level']);
$this->assertRegExp('/\[ERROR\] The following exception prevented the route to be matched against application routes: "Unable to get a property on a non-object\." \(in .* line \d+\)/', $traces[0]['log']);
}
}
0