Skip to content
Snippets Groups Projects
Commit d6cf5bd3 authored by Benni Mack's avatar Benni Mack
Browse files

[BUGFIX] Throw proper exception when parsing Yaml files

When having an empty Yaml file, the error that is thrown isn't
helpful for the developer, and in case of RTE, the RTE is not shown
at all.

Resolves: #81557
Releases: master, 8.7
Change-Id: Ie435b9f42623962637a9ead0243be6cde15c82c6
Reviewed-on: https://review.typo3.org/53197


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: default avatarJosef Glatz <josef.glatz@typo3.org>
Tested-by: default avatarJosef Glatz <josef.glatz@typo3.org>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent 3848b738
Branches
Tags
No related merge requests found
......@@ -18,7 +18,7 @@ use Symfony\Component\Yaml\Yaml;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A Yaml file loader that allows to load YML files, based on the Symfony/Yaml component
* A Yaml file loader that allows to load YAML files, based on the Symfony/Yaml component
*
* In addition to just load a yaml file, it adds some special functionality.
*
......@@ -39,12 +39,17 @@ class YamlFileLoader
*
* @param string $fileName either relative to PATH_site or prefixed with EXT:...
* @return array the configuration as array
* @throws \RuntimeException when the file is empty or is of invalid format
*/
public function load(string $fileName): array
{
$content = $this->getFileContents($fileName);
$content = Yaml::parse($content);
if (!is_array($content)) {
throw new \RuntimeException('YAML file "' . $fileName . '" could not be parsed into valid syntax, probably empty?', 1497332874);
}
$content = $this->processImports($content);
// Check for "%" placeholders
......@@ -63,11 +68,11 @@ class YamlFileLoader
*/
protected function getFileContents(string $fileName): string
{
$fileName = GeneralUtility::getFileAbsFileName($fileName);
if (!$fileName) {
$streamlinedFileName = GeneralUtility::getFileAbsFileName($fileName);
if (!$streamlinedFileName) {
throw new \RuntimeException('YAML File "' . $fileName . '" could not be loaded', 1485784246);
}
return file_get_contents($fileName);
return file_get_contents($streamlinedFileName);
}
/**
......
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