Skip to content

Commit e937b2b

Browse files
committed
Throwing exception when the configuration cannot be parsed properly.
There the easy case when the parser actualy detect the error and we pass along his exception and there is the edge case when there is only one line of config that can be interpreted as a string by the parser.
1 parent 349740d commit e937b2b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Dflydev/DotAccessConfiguration/YamlConfigurationBuilder.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Dflydev\DotAccessConfiguration;
1313

14+
use Psr\Log\InvalidArgumentException;
1415
use Symfony\Component\Yaml\Yaml;
1516

1617
class YamlConfigurationBuilder extends AbstractConfigurationBuilder
@@ -38,7 +39,16 @@ public function __construct($input = null)
3839
public function internalBuild(ConfigurationInterface $configuration)
3940
{
4041
if (null !== $this->input) {
41-
$configuration->importRaw(Yaml::parse($this->input));
42+
try{
43+
$yml = Yaml::parse($this->input, true);
44+
} catch (\Exception $e) {
45+
throw new InvalidArgumentException($e->getMessage(), 0, $e);
46+
}
47+
if (is_string($yml))
48+
{
49+
throw(new \InvalidArgumentException('Yaml could not be parsed, parser detected a string.'));
50+
}
51+
$configuration->importRaw($yml);
4252
}
4353
}
4454
}

0 commit comments

Comments
 (0)