Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aeb9bff

Browse filesBrowse files
committed
added a more specialized exception for a better error message
1 parent 7b8409a commit aeb9bff
Copy full SHA for aeb9bff

File tree

7 files changed

+27
-7
lines changed
Filter options

7 files changed

+27
-7
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function load($resource, $type = null)
6464
// - this handles the case and prevents the second fatal error
6565
// by triggering an exception beforehand.
6666

67-
throw new FileLoaderLoadException($resource);
67+
throw new FileLoaderLoadException($resource, null, null, null, $type);
6868
}
6969
$this->loading = true;
7070

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Exception/FileLoaderLoadException.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ class FileLoaderLoadException extends \Exception
2323
* @param string $sourceResource The original resource importing the new resource
2424
* @param int $code The error code
2525
* @param \Exception $previous A previous exception
26+
* @param string $type The type of resource
2627
*/
27-
public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
28+
public function __construct($resource, $sourceResource = null, $code = null, $previous = null, $type = null)
2829
{
2930
$message = '';
3031
if ($previous) {
@@ -60,6 +61,13 @@ public function __construct($resource, $sourceResource = null, $code = null, $pr
6061
$bundle = substr($parts[0], 1);
6162
$message .= sprintf(' Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
6263
$message .= sprintf(' If the bundle is registered, make sure the bundle path "%s" is not empty.', $resource);
64+
} elseif (null !== $type) {
65+
// maybe there is no loader for this specific type
66+
if ('annotation' === $type) {
67+
$message .= ' Make sure annotations are enabled.';
68+
} else {
69+
$message .= sprintf(' Make sure there is a loader supporting the "%s" type.', $type);
70+
}
6371
}
6472

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

‎src/Symfony/Component/Config/Loader/DelegatingLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Loader/DelegatingLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(LoaderResolverInterface $resolver)
3939
public function load($resource, $type = null)
4040
{
4141
if (false === $loader = $this->resolver->resolve($resource, $type)) {
42-
throw new FileLoaderLoadException($resource);
42+
throw new FileLoaderLoadException($resource, null, null, null, $type);
4343
}
4444

4545
return $loader->load($resource, $type);

‎src/Symfony/Component/Config/Loader/FileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Loader/FileLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private function doImport($resource, $type = null, $ignoreErrors = false, $sourc
210210
throw $e;
211211
}
212212

213-
throw new FileLoaderLoadException($resource, $sourceResource, null, $e);
213+
throw new FileLoaderLoadException($resource, $sourceResource, null, $e, $type);
214214
}
215215
}
216216
}

‎src/Symfony/Component/Config/Loader/Loader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Loader/Loader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function resolve($resource, $type = null)
7070
$loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
7171

7272
if (false === $loader) {
73-
throw new FileLoaderLoadException($resource);
73+
throw new FileLoaderLoadException($resource, null, null, null, $type);
7474
}
7575

7676
return $loader;

‎src/Symfony/Component/Config/Tests/Exception/FileLoaderLoadExceptionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Exception/FileLoaderLoadExceptionTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ public function testMessageCannotLoadResource()
2222
$this->assertEquals('Cannot load resource "resource".', $exception->getMessage());
2323
}
2424

25+
public function testMessageCannotLoadResourceWithType()
26+
{
27+
$exception = new FileLoaderLoadException('resource', null, null, null, 'foobar');
28+
$this->assertEquals('Cannot load resource "resource". Make sure there is a loader supporting the "foobar" type.', $exception->getMessage());
29+
}
30+
31+
public function testMessageCannotLoadResourceWithAnnotationType()
32+
{
33+
$exception = new FileLoaderLoadException('resource', null, null, null, 'annotation');
34+
$this->assertEquals('Cannot load resource "resource". Make sure annotations are enabled.', $exception->getMessage());
35+
}
36+
2537
public function testMessageCannotImportResourceFromSource()
2638
{
2739
$exception = new FileLoaderLoadException('resource', 'sourceResource');

‎src/Symfony/Component/Routing/RouteCollectionBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/RouteCollectionBuilder.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ private function load($resource, $type = null)
369369
}
370370

371371
if (null === $resolver = $this->loader->getResolver()) {
372-
throw new FileLoaderLoadException($resource);
372+
throw new FileLoaderLoadException($resource, null, null, null, $type);
373373
}
374374

375375
if (false === $loader = $resolver->resolve($resource, $type)) {
376-
throw new FileLoaderLoadException($resource);
376+
throw new FileLoaderLoadException($resource, null, null, null, $type);
377377
}
378378

379379
$collections = $loader->load($resource, $type);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.