Commit e53445ef authored by catch's avatar catch
Browse files

Issue #3283035 by bruno.bicudo, Spokje, _pratik_, longwave, joachim, xjm,...

Issue #3283035 by bruno.bicudo, Spokje, _pratik_, longwave, joachim, xjm, smustgrave: Exceptions from errors in services.yml files should tell you which file
parent 373c3da2
Loading
Loading
Loading
Loading
+9 −1
Changes for core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
namespace Drupal\Core\DependencyInjection;

use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Core\Serialization\Yaml;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -414,7 +415,14 @@ protected function loadFile($file)
            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
        }

        return $this->validate(Yaml::decode(file_get_contents($file)), $file);
        try {
          $valid_file = $this->validate(Yaml::decode(file_get_contents($file)), $file);
        }
        catch (InvalidDataTypeException $e) {
          throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $file) . $e->getMessage());
        }

        return $valid_file;
    }

    /**
+6 −0
Changes for core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -169,6 +169,12 @@ public function providerTestExceptions() {
YAML,
        'A service definition must be an array or a string starting with "@" but string found for service "service" in vfs://drupal/modules/example/example.yml. Check your YAML syntax.',
      ],
      'YAML must be valid' => [<<<YAML
   do not:
      do this for the love of Foo Bar!
YAML,
        'The file "vfs://drupal/modules/example/example.yml" does not contain valid YAML',
      ],
    ];
  }