Skip to content

Commit 6dc51cf

Browse files
committed
improve exceptions when parsing malformed files
1 parent fbadda8 commit 6dc51cf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Loader/YamlFileLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Routing\RouteCollection;
1515
use Symfony\Component\Routing\Route;
1616
use Symfony\Component\Config\Resource\FileResource;
17+
use Symfony\Component\Yaml\Exception\ParseException;
1718
use Symfony\Component\Yaml\Parser as YamlParser;
1819
use Symfony\Component\Config\Loader\FileLoader;
1920

@@ -60,7 +61,11 @@ public function load($file, $type = null)
6061
$this->yamlParser = new YamlParser();
6162
}
6263

63-
$config = $this->yamlParser->parse(file_get_contents($path));
64+
try {
65+
$config = $this->yamlParser->parse(file_get_contents($path));
66+
} catch (ParseException $e) {
67+
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
68+
}
6469

6570
$collection = new RouteCollection();
6671
$collection->addResource(new FileResource($path));

0 commit comments

Comments
 (0)