diff --git a/core/lib/Drupal/Core/Asset/Exception/InvalidCssCategoryException.php b/core/lib/Drupal/Core/Asset/Exception/InvalidCssCategoryException.php
new file mode 100644
index 0000000..b128324
--- /dev/null
+++ b/core/lib/Drupal/Core/Asset/Exception/InvalidCssCategoryException.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Asset\Exception\InvalidCssCategoryException.
+ */
+
+namespace Drupal\Core\Asset\Exception;
+
+/**
+ * Defines an exception if the library file does not specify a valid category.
+ */
+class InvalidCssCategoryException extends \RunTimeException {
+
+}
diff --git a/core/lib/Drupal/Core/Asset/Exception/InvalidDefinitionOfCssException.php b/core/lib/Drupal/Core/Asset/Exception/InvalidDefinitionOfCssException.php
new file mode 100644
index 0000000..52d5b5a
--- /dev/null
+++ b/core/lib/Drupal/Core/Asset/Exception/InvalidDefinitionOfCssException.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Asset\Exception\InvalidDefinitionOfCssException.
+ */
+
+namespace Drupal\Core\Asset\Exception;
+
+/**
+ * Defines an exception if the library file is not keyed by a category.
+ */
+class InvalidDefinitionOfCssException extends \RunTimeException {
+
+}
diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
index 5ca5f26..7ea5522 100644
--- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
+++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
@@ -8,6 +8,8 @@
 namespace Drupal\Core\Asset;
 
 use Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException;
+use Drupal\Core\Asset\Exception\InvalidCssCategoryException;
+use Drupal\Core\Asset\Exception\InvalidDefinitionOfCssException;
 use Drupal\Core\Asset\Exception\InvalidLibraryFileException;
 use Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException;
 use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -118,12 +120,21 @@ public function buildByExtension($extension) {
         //   and only once prior to rendering out an HTML page.
         if ($type == 'css' && !empty($library[$type])) {
           foreach ($library[$type] as $category => $files) {
+            if (empty($files)) {
+              throw new InvalidDefinitionOfCssException(sprintf("You have to key the css files in the %s.library.yml file by category ('%s' seems to be a file name, allowed categories are Base, Layout, Component, State, Theme)", $extension, $category));
+            }
             foreach ($files as $source => $options) {
               if (!isset($options['weight'])) {
                 $options['weight'] = 0;
               }
-              // Apply the corresponding weight defined by CSS_* constants.
-              $options['weight'] += constant('CSS_' . strtoupper($category));
+              //Check if the category is valid or not and
+              //  apply the corresponding weight defined by CSS_* constants.
+              if (defined('CSS_' . strtoupper($category))) {
+                $options['weight'] += constant('CSS_' . strtoupper($category));
+              }
+              else {
+                throw new InvalidCssCategoryException(sprintf("You have used an invalid category %s in %s.libraries.yml. Allowed categories are Base, Layout, Component, State, Theme)", $category, $extension));
+              }
               $library[$type][$source] = $options;
             }
             unset($library[$type][$category]);
