diff --git a/src/i18n/Messages/YamlReader.php b/src/i18n/Messages/YamlReader.php index 879ea0a27..7b4939843 100644 --- a/src/i18n/Messages/YamlReader.php +++ b/src/i18n/Messages/YamlReader.php @@ -39,7 +39,7 @@ class YamlReader implements Reader // Normalise messages return $this->normaliseMessages($yaml[$locale]); } catch (ParseException $exception) { - throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $path), 0, $exception); + throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s". Message: %s', $path, $exception->getMessage()), 0, $exception); } } diff --git a/tests/php/i18n/YamlReaderTest.php b/tests/php/i18n/YamlReaderTest.php index 36d9b71ea..1487979e3 100644 --- a/tests/php/i18n/YamlReaderTest.php +++ b/tests/php/i18n/YamlReaderTest.php @@ -4,6 +4,7 @@ namespace SilverStripe\i18n\Tests; use SilverStripe\Dev\SapphireTest; use SilverStripe\i18n\Messages\YamlReader; +use Symfony\Component\Translation\Exception\InvalidResourceException; class YamlReaderTest extends SapphireTest { @@ -38,4 +39,15 @@ class YamlReaderTest extends SapphireTest ]; $this->assertEquals($expected, $output); } + + + public function testThrowsMeaningfulExceptionWhenYmlIsCorrupted() + { + $path = __DIR__ . '/i18nTest/_fakewebroot/i18ntestmodule/lang/en_corrupt.yml'; + $this->expectException(InvalidResourceException::class); + $regex_path = str_replace('.', '\.', $path); + $this->expectExceptionMessageRegExp('@^Error parsing YAML, invalid file "' . $regex_path . '"\. Message: ([\w ].*) line 5 @'); + $reader = new YamlReader(); + $reader->read('en', $path); + } } diff --git a/tests/php/i18n/i18nTest/_fakewebroot/i18ntestmodule/lang/en_corrupt.yml b/tests/php/i18n/i18nTest/_fakewebroot/i18ntestmodule/lang/en_corrupt.yml new file mode 100644 index 000000000..62ee7f2a4 --- /dev/null +++ b/tests/php/i18n/i18nTest/_fakewebroot/i18ntestmodule/lang/en_corrupt.yml @@ -0,0 +1,5 @@ +en: + NONAMESPACE: Include Entity without Namespace + Invalid: Foo + About: 'About us' + - Invalid # this should throw "A colon cannot be used in an unquoted mapping value at line 5"