ISSUE #11300: Improve Routing Syntax Import Error
modified FileLoaderLoadException message to present the previous (Parse)Exception first
This commit is contained in:
parent
8b54211471
commit
8ac5275751
@ -26,20 +26,42 @@ class FileLoaderLoadException extends \Exception
|
|||||||
*/
|
*/
|
||||||
public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
|
public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
|
||||||
{
|
{
|
||||||
if (null === $sourceResource) {
|
$message = '';
|
||||||
$message = sprintf('Cannot load resource "%s".', $this->varToString($resource));
|
if ($previous) {
|
||||||
|
// include the previous exception, to help the user see what might be the underlying cause
|
||||||
|
|
||||||
|
//Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
|
||||||
|
if ('.' === substr($previous->getMessage(), -1)) {
|
||||||
|
$trimmedMessage = substr($previous->getMessage(), 0, -1);
|
||||||
|
$message .= ' ' . sprintf('%s', $trimmedMessage) . ' in ';
|
||||||
|
} else {
|
||||||
|
$message .= ' ' . sprintf('%s', $previous->getMessage()) . ' in ';
|
||||||
|
}
|
||||||
|
$message .= $resource . ' ';
|
||||||
|
|
||||||
|
// show tweaked trace to complete the human readable sentence
|
||||||
|
if (null === $sourceResource) {
|
||||||
|
$message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
|
||||||
|
} else {
|
||||||
|
$message .= sprintf(
|
||||||
|
'(which is being imported from "%s")',
|
||||||
|
$this->varToString($sourceResource)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$message .= '.';
|
||||||
|
|
||||||
|
// if there's no previous message, present it the default way
|
||||||
|
} elseif (null === $sourceResource) {
|
||||||
|
$message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
|
||||||
} else {
|
} else {
|
||||||
$message = sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
|
$message .= sprintf('Cannot import resource "%s" from "%s".',$this->varToString($resource),$this->varToString($sourceResource));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the resource located inside a bundle?
|
// Is the resource located inside a bundle?
|
||||||
if ('@' === $resource[0]) {
|
if ('@' === $resource[0]) {
|
||||||
$parts = explode(DIRECTORY_SEPARATOR, $resource);
|
$parts = explode(DIRECTORY_SEPARATOR, $resource);
|
||||||
$bundle = substr($parts[0], 1);
|
$bundle = substr($parts[0], 1);
|
||||||
$message .= ' '.sprintf('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
|
$message .= ' ' . sprintf('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.',$bundle);
|
||||||
} elseif ($previous) {
|
|
||||||
// include the previous exception, to help the user see what might be the underlying cause
|
|
||||||
$message .= ' '.sprintf('(%s)', $previous->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
|
Reference in New Issue
Block a user