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 26ba97a..09c4e84 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;
@@ -122,12 +124,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]);
diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module
index 5c35856..1195374 100644
--- a/core/modules/system/tests/modules/common_test/common_test.module
+++ b/core/modules/system/tests/modules/common_test/common_test.module
@@ -174,9 +174,9 @@ function common_test_library_info_build() {
   if (\Drupal::state()->get('common_test.library_info_build_test')) {
     $libraries['dynamic_library'] = [
       'version' => '1.0',
-      'css' => [
+      'css' => ['theme' => [
         'common_test.css' => [],
-      ],
+      ]],
     ];
   }
   return $libraries;
diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml
index 9a8b4dd..169d2f4 100644
--- a/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml
+++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml
@@ -1,6 +1,7 @@
 example:
   css:
-    css/example.js: {}
+    theme:
+      css/example.css: {}
   dependencies:
     - external/example_external
     - example_module/example
