Skip to content

Commit

Permalink
Show warnings if config could not be read
Browse files Browse the repository at this point in the history
  • Loading branch information
nhovratov committed Dec 9, 2024
1 parent a588b4c commit ad95cc5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Classes/Command/CreateContentBlockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw new \RuntimeException('No packages were found in which to store the Content Block.', 1678699706);
}
$configPath = $input->getOption('config-path');
$defaults = $this->loadDefaultsFromContentBlocksConfig($configPath);
$defaults = $this->loadDefaultsFromContentBlocksConfig($configPath, $output);

if ($input->getOption('content-type')) {
$contentTypeFromInput = $input->getOption('content-type');
Expand Down Expand Up @@ -307,7 +307,7 @@ protected function getExtPath(string $extension, ContentType $contentType): stri
* extension: ?string
* }
*/
private function loadDefaultsFromContentBlocksConfig(?string $configPath): array
private function loadDefaultsFromContentBlocksConfig(?string $configPath, OutputInterface $output): array
{
$config = [
'content-type' => 'content-element',
Expand All @@ -326,9 +326,14 @@ private function loadDefaultsFromContentBlocksConfig(?string $configPath): array
}
try {
$yaml = Yaml::parseFile($path);
} catch (ParseException) {
} catch (ParseException $e) {
$output->writeln('<bg=yellow;options=bold>Warning: Error occurred parsing default config in "' . $configFile . '".</>');
$output->writeln('<bg=yellow;options=bold>Message: ' . $e->getMessage() . '</>');
return $config;
}
if (!is_array($yaml)) {
$output->writeln('<bg=yellow;options=bold>Warning: Expected default config to be array in "' . $configFile . '".</>');
}
foreach (array_keys($config) as $key) {
$config[$key] = $yaml[$key] ?? $config[$key];
}
Expand Down

0 comments on commit ad95cc5

Please sign in to comment.