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

Skip to content

Commit 8ac5275

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

File tree

1 file changed

+29
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,42 @@ 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+
33+
//Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
34+
if ('.' === substr($previous->getMessage(), -1)) {
35+
$trimmedMessage = substr($previous->getMessage(), 0, -1);
36+
$message .= ' ' . sprintf('%s', $trimmedMessage) . ' in ';
37+
} else {
38+
$message .= ' ' . sprintf('%s', $previous->getMessage()) . ' in ';
39+
}
40+
$message .= $resource . ' ';
41+
42+
// show tweaked trace to complete the human readable sentence
43+
if (null === $sourceResource) {
44+
$message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
45+
} else {
46+
$message .= sprintf(
47+
'(which is being imported from "%s")',
48+
$this->varToString($sourceResource)
49+
);
50+
}
51+
$message .= '.';
52+
53+
// if there's no previous message, present it the default way
54+
} elseif (null === $sourceResource) {
55+
$message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
3156
} else {
32-
$message = sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
57+
$message .= sprintf('Cannot import resource "%s" from "%s".',$this->varToString($resource),$this->varToString($sourceResource));
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('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.',$bundle);
4365
}
4466

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