Issue #2267039 by aerozeppelin, joachim: UnsupportedDataTypeConfigException doesn't say which config file the problem is
parent
eed2f22e86
commit
40bf8be87c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue