From 40bf8be87c4613ce44a0c78d682e656e17f66c5e Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Mon, 1 Feb 2016 19:17:33 +0900 Subject: [PATCH] Issue #2267039 by aerozeppelin, joachim: UnsupportedDataTypeConfigException doesn't say which config file the problem is --- core/lib/Drupal/Core/Config/FileStorage.php | 5 +++-- .../config/src/Tests/Storage/FileStorageTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index c630fec2e59..03b0464b5ba 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -95,12 +95,13 @@ class FileStorage implements StorageInterface { if (!$this->exists($name)) { return FALSE; } - $data = file_get_contents($this->getFilePath($name)); + $filepath = $this->getFilePath($name); + $data = file_get_contents($filepath); try { $data = $this->decode($data); } catch (InvalidDataTypeException $e) { - throw new UnsupportedDataTypeConfigException("Invalid data type in config $name: {$e->getMessage()}"); + throw new UnsupportedDataTypeConfigException('Invalid data type in config ' . $name . ', found in file' . $filepath . ' : ' . $e->getMessage()); } return $data; } diff --git a/core/modules/config/src/Tests/Storage/FileStorageTest.php b/core/modules/config/src/Tests/Storage/FileStorageTest.php index 932c54e6297..fb17f1e14e3 100644 --- a/core/modules/config/src/Tests/Storage/FileStorageTest.php +++ b/core/modules/config/src/Tests/Storage/FileStorageTest.php @@ -9,6 +9,7 @@ namespace Drupal\config\Tests\Storage; use Drupal\Component\Serialization\Yaml; use Drupal\Core\Config\FileStorage; +use Drupal\Core\Config\UnsupportedDataTypeConfigException; /** * Tests FileStorage operations. @@ -76,4 +77,19 @@ class FileStorageTest extends ConfigStorageTestBase { $this->assertIdentical($config_files, $expected_files, 'Absolute path, two config files found.'); } + /** + * Test UnsupportedDataTypeConfigException displays path of + * erroneous file during read. + */ + public function testReadUnsupportedDataTypeConfigException() { + file_put_contents($this->storage->getFilePath('core.extension'), PHP_EOL . 'foo : [bar}', FILE_APPEND); + try { + $config_parsed = $this->storage->read('core.extension'); + } + catch (UnsupportedDataTypeConfigException $e) { + $this->pass('Exception thrown when trying to read a field containing invalid data type.'); + $this->assertTrue((strpos($e->getMessage(), $this->storage->getFilePath('core.extension')) !== FALSE), 'Erroneous file path is displayed.'); + } + } + }