diff --git a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
index 159f643166b922961772acbdb484b201cf935ba8..879966fda0293451fc6250559dfa9c18dcc8d28e 100644
--- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
+++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
@@ -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;
     }
 
     /**
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php
index 7354d304c3d959a3078c840ec0a2879ce983c8d7..54d996bd07b6813143d65fb5da4d832b93e17180 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php
@@ -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',
+      ],
     ];
   }