@@ -26,20 +26,42 @@ class FileLoaderLoadException extends \Exception
26
26
*/
27
27
public function __construct ($ resource , $ sourceResource = null , $ code = null , $ previous = null )
28
28
{
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 ));
31
56
} 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 ));
33
58
}
34
59
35
60
// Is the resource located inside a bundle?
36
61
if ('@ ' === $ resource [0 ]) {
37
62
$ parts = explode (DIRECTORY_SEPARATOR , $ resource );
38
63
$ 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 );
43
65
}
44
66
45
67
parent ::__construct ($ message , $ code , $ previous );
0 commit comments