bug #36501 [DX] Show the ParseException message in all YAML file loaders (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[DX] Show the ParseException message in all YAML file loaders

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

This PR synchronizes the exception message in the Routing, Validator and Translation YAML file loaders with the DependencyInjection YAML file loader behavior. Adding the ParseException message is a big DX gain because it highlights the problem directly instead of having to scroll down 7 previous exceptions.

I'm targetting 3.4 because DX can be considered as a bug fix AFAIK.

Commits
-------

fc6cf3d3c6 [DX] Show the ParseException message in YAML file loaders
This commit is contained in:
Nicolas Grekas 2020-05-04 15:29:28 +02:00
commit 78a7f4682f
4 changed files with 4 additions and 4 deletions

View File

@ -660,7 +660,7 @@ class YamlFileLoader extends FileLoader
try {
$configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
} catch (ParseException $e) {
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: '.$e->getMessage(), $file), 0, $e);
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML', $file).': '.$e->getMessage(), 0, $e);
} finally {
restore_error_handler();
}

View File

@ -66,7 +66,7 @@ class YamlFileLoader extends FileLoader
try {
$parsedConfig = $this->yamlParser->parseFile($path);
} catch (ParseException $e) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML', $path).': '.$e->getMessage(), 0, $e);
} finally {
restore_error_handler();
}

View File

@ -47,7 +47,7 @@ class YamlFileLoader extends FileLoader
try {
$messages = $this->yamlParser->parseFile($resource);
} catch (ParseException $e) {
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s".', $resource), 0, $e);
throw new InvalidResourceException(sprintf('The file "%s" does not contain valid YAML', $resource).': '.$e->getMessage(), 0, $e);
} finally {
restore_error_handler();
}

View File

@ -124,7 +124,7 @@ class YamlFileLoader extends FileLoader
try {
$classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML', $path).': '.$e->getMessage(), 0, $e);
} finally {
restore_error_handler();
}