@@ -26,20 +26,45 @@ 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
+ 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 ));
31
52
} 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
+ );
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 (
65
+ ' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class. ' ,
66
+ $ bundle
67
+ );
43
68
}
44
69
45
70
parent ::__construct ($ message , $ code , $ previous );
0 commit comments