Commit 40bf8be8 authored by catch's avatar catch

Issue #2267039 by aerozeppelin, joachim: UnsupportedDataTypeConfigException...

Issue #2267039 by aerozeppelin, joachim: UnsupportedDataTypeConfigException doesn't say which config file the problem is
parent eed2f22e
...@@ -95,12 +95,13 @@ public function read($name) { ...@@ -95,12 +95,13 @@ public function read($name) {
if (!$this->exists($name)) { if (!$this->exists($name)) {
return FALSE; return FALSE;
} }
$data = file_get_contents($this->getFilePath($name)); $filepath = $this->getFilePath($name);
$data = file_get_contents($filepath);
try { try {
$data = $this->decode($data); $data = $this->decode($data);
} }
catch (InvalidDataTypeException $e) { 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; return $data;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Component\Serialization\Yaml; use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\UnsupportedDataTypeConfigException;
/** /**
* Tests FileStorage operations. * Tests FileStorage operations.
...@@ -76,4 +77,19 @@ public function testlistAll() { ...@@ -76,4 +77,19 @@ public function testlistAll() {
$this->assertIdentical($config_files, $expected_files, 'Absolute path, two config files found.'); $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.');
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment