8000 ISSUE #11300: Improve Routing Syntax Import Error · JanDC/symfony@2126371 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2126371

Browse files
committed
ISSUE symfony#11300: Improve Routing Syntax Import Error
modified FileLoaderLoadException message to present the previous (Parse)Exception first
1 parent 8b54211 commit 2126371

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/Symfony/Component/Config/Exception/FileLoaderLoadException.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,45 @@ class FileLoaderLoadException extends \Exception
2626
*/
2727
public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
2828
{
29-
if (null === $sourceResource) {
30-
$message = sprintf('Cannot load resource "%s".', $this->varToString($resource));
29+
$message = '';
30+
if ($previous) {
31+
// include the previous exception, to help the user see what might be the underlying cause
32+
if ('.' === substr($previous->getMessage(), -1)) {
33+
$trimmedMessage = substr($previous->getMessage(), 0, -1);
34+
$message .= ' ' . sprintf('%s', $trimmedMessage) . ' in ';
35+
} else {
36+
$message .= ' ' . sprintf('%s', $previous->getMessage()) . ' in ';
37+
}
38+
$message .= $resource . '. ';
39+
// show tweaked trace
40+
if (null === $sourceResource) {
41+
$message .= sprintf('(Which is loaded in resource "%s")', $this->varToString($resource));
42+
} else {
43+
$message .= sprintf(
44+
'(Which is being imported from "%s")',
45+
$this->varToString($sourceResource)
46+
);
47+
}
48+
49+
// if there's no previous message, present it the default way
50+
} elseif (null === $sourceResource) {
51+
$message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
3152
} else {
32-
$message = sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
53+
$message .= sprintf(
54+
'Cannot import resource "%s" from "%s".',
55+
$this->varToString($resource),
56+
$this->varToString($sourceResource)
57+
);
3358
}
3459

3560
// Is the resource located inside a bundle?
3661
if ('@' === $resource[0]) {
3762
$parts = explode(DIRECTORY_SEPARATOR, $resource);
3863
$bundle = substr($parts[0], 1);
39-
$message .= ' '.sprintf('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
40-
} elseif ($previous) {
41-
// include the previous exception, to help the user see what might be the underlying cause
42-
$message .= ' '.sprintf('(%s)', $previous->getMessage());
64+
$message .= ' ' . sprintf(
65+
'Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.',
66+
$bundle
67+
);
4368
}
4469

4570
parent::__construct($message, $code, $previous);

0 commit comments

Comments
 (0)
0