Skip to content

Commit 5e81680

Browse files
committed
bug #15731 improve exceptions when parsing malformed files (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- improve exceptions when parsing malformed files | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15702 | License | MIT | Doc PR | Commits ------- 3849cd8 improve exceptions when parsing malformed files
2 parents becce5a + d7499f1 commit 5e81680

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Mapping/Loader/YamlFileLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Mapping\Loader;
1313

1414
use Symfony\Component\Validator\Mapping\ClassMetadata;
15+
use Symfony\Component\Yaml\Exception\ParseException;
1516
use Symfony\Component\Yaml\Parser as YamlParser;
1617

1718
/**
@@ -117,7 +118,11 @@ protected function parseNodes(array $nodes)
117118
*/
118119
private function parseFile($path)
119120
{
120-
$classes = $this->yamlParser->parse(file_get_contents($path));
121+
try {
122+
$classes = $this->yamlParser->parse(file_get_contents($path));
123+
} catch (ParseException $e) {
124+
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid.', $path), 0, $e);
125+
}
121126

122127
// empty file
123128
if (null === $classes) {

0 commit comments

Comments
 (0)