Repository: webpack-contrib/mini-css-extract-plugin (js)

Issue:
Error type not propagated
The webpack script loading error handling propagates the `Error.type`: https://github.com/webpack/webpack/blob/v4.8.3/lib/web/JsonpMainTemplatePlugin.js#L187-L192

Would be nice if the same was done for the css `<link>` load errors: https://github.com/webpack-contrib/mini-css-extract-plugin/blob/v0.4.0/src/index.js#L303-L309

Pull request description:
feat: added the `type` property for loading errors
<!--
  HOLY CRAP a Pull Request. We ❤️ those!

  If you remove or skip this template, you'll make the 🐼 sad and the mighty god
  of Github will appear and pile-drive the close button from a great height
  while making animal noises.

  Please place an x (no spaces!) in all [ ] that apply
-->

This PR contains a:

- [ ] **bugfix**
- [x] new **feature**
- [ ] **code refactor**
- [x] **test update** <!-- if bug or feature is checked, this should be too -->
- [ ] **typo fix**
- [ ] **metadata update**

### Motivation / Use-Case

fixes #152

### Breaking Changes

No

### Additional Info

No

Patch:
diff --git a/src/CssLoadingRuntimeModule.js b/src/CssLoadingRuntimeModule.js
index 1063351..ce16abc 100644
--- a/src/CssLoadingRuntimeModule.js
+++ b/src/CssLoadingRuntimeModule.js
@@ -67,10 +67,12 @@ module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
             Template.indent(['resolve();']),
             '} else {',
             Template.indent([
-              'var request = event && event.target && event.target.href || fullhref;',
-              'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");',
+              "var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
+              'var realHref = event && event.target && event.target.href || fullhref;',
+              'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + realHref + ")");',
               'err.code = "CSS_CHUNK_LOAD_FAILED";',
-              'err.request = request;',
+              'err.type = errorType;',
+              'err.request = realHref;',
               'linkTag.parentNode.removeChild(linkTag)',
               'reject(err);',
             ]),
diff --git a/src/index.js b/src/index.js
index cda0bf0..95c5798 100644
--- a/src/index.js
+++ b/src/index.js
@@ -413,10 +413,12 @@ class MiniCssExtractPlugin {
                       Template.indent(['resolve();']),
                       '} else {',
                       Template.indent([
-                        'var request = event && event.target && event.target.href || fullhref;',
-                        'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");',
+                        "var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
+                        'var realHref = event && event.target && event.target.href || fullhref;',
+                        'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + realHref + ")");',
                         'err.code = "CSS_CHUNK_LOAD_FAILED";',
-                        'err.request = request;',
+                        'err.type = errorType;',
+                        'err.request = realHref;',
                         'delete installedCssChunks[chunkId]',
                         'linkTag.parentNode.removeChild(linkTag)',
                         'reject(err);',


Test patch:
diff --git a/test/cases/hmr/expected/webpack-5/main.js b/test/cases/hmr/expected/webpack-5/main.js
index b746eb6..1e9f0d4 100644
--- a/test/cases/hmr/expected/webpack-5/main.js
+++ b/test/cases/hmr/expected/webpack-5/main.js
@@ -833,10 +833,12 @@ module.exports = function (urlString) {
 /******/ 				if (event.type === 'load') {
 /******/ 					resolve();
 /******/ 				} else {
-/******/ 					var request = event && event.target && event.target.href || fullhref;
-/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 					var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 					var realHref = event && event.target && event.target.href || fullhref;
+/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 					err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 					err.request = request;
+/******/ 					err.type = errorType;
+/******/ 					err.request = realHref;
 /******/ 					linkTag.parentNode.removeChild(linkTag)
 /******/ 					reject(err);
 /******/ 				}
diff --git a/test/cases/insert-function/expected/webpack-4/main.js b/test/cases/insert-function/expected/webpack-4/main.js
index 45c2e3d..469a9aa 100644
--- a/test/cases/insert-function/expected/webpack-4/main.js
+++ b/test/cases/insert-function/expected/webpack-4/main.js
@@ -110,10 +110,12 @@
 /******/ 					if (event.type === 'load') {
 /******/ 						resolve();
 /******/ 					} else {
-/******/ 						var request = event && event.target && event.target.href || fullhref;
-/******/ 						var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 						var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 						var realHref = event && event.target && event.target.href || fullhref;
+/******/ 						var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 						err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 						err.request = request;
+/******/ 						err.type = errorType;
+/******/ 						err.request = realHref;
 /******/ 						delete installedCssChunks[chunkId]
 /******/ 						linkTag.parentNode.removeChild(linkTag)
 /******/ 						reject(err);
diff --git a/test/cases/insert-function/expected/webpack-5/main.js b/test/cases/insert-function/expected/webpack-5/main.js
index 55507ce..80c5cb0 100644
--- a/test/cases/insert-function/expected/webpack-5/main.js
+++ b/test/cases/insert-function/expected/webpack-5/main.js
@@ -168,10 +168,12 @@
 /******/ 				if (event.type === 'load') {
 /******/ 					resolve();
 /******/ 				} else {
-/******/ 					var request = event && event.target && event.target.href || fullhref;
-/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 					var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 					var realHref = event && event.target && event.target.href || fullhref;
+/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 					err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 					err.request = request;
+/******/ 					err.type = errorType;
+/******/ 					err.request = realHref;
 /******/ 					linkTag.parentNode.removeChild(linkTag)
 /******/ 					reject(err);
 /******/ 				}
diff --git a/test/cases/insert-string/expected/webpack-4/main.js b/test/cases/insert-string/expected/webpack-4/main.js
index fa47844..9af8b29 100644
--- a/test/cases/insert-string/expected/webpack-4/main.js
+++ b/test/cases/insert-string/expected/webpack-4/main.js
@@ -110,10 +110,12 @@
 /******/ 					if (event.type === 'load') {
 /******/ 						resolve();
 /******/ 					} else {
-/******/ 						var request = event && event.target && event.target.href || fullhref;
-/******/ 						var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 						var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 						var realHref = event && event.target && event.target.href || fullhref;
+/******/ 						var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 						err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 						err.request = request;
+/******/ 						err.type = errorType;
+/******/ 						err.request = realHref;
 /******/ 						delete installedCssChunks[chunkId]
 /******/ 						linkTag.parentNode.removeChild(linkTag)
 /******/ 						reject(err);
diff --git a/test/cases/insert-string/expected/webpack-5/main.js b/test/cases/insert-string/expected/webpack-5/main.js
index 9d78db3..46fb519 100644
--- a/test/cases/insert-string/expected/webpack-5/main.js
+++ b/test/cases/insert-string/expected/webpack-5/main.js
@@ -168,10 +168,12 @@
 /******/ 				if (event.type === 'load') {
 /******/ 					resolve();
 /******/ 				} else {
-/******/ 					var request = event && event.target && event.target.href || fullhref;
-/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 					var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 					var realHref = event && event.target && event.target.href || fullhref;
+/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 					err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 					err.request = request;
+/******/ 					err.type = errorType;
+/******/ 					err.request = realHref;
 /******/ 					linkTag.parentNode.removeChild(linkTag)
 /******/ 					reject(err);
 /******/ 				}
diff --git a/test/cases/insert-undefined/expected/webpack-4/main.js b/test/cases/insert-undefined/expected/webpack-4/main.js
index 4ad5b42..dffcd67 100644
--- a/test/cases/insert-undefined/expected/webpack-4/main.js
+++ b/test/cases/insert-undefined/expected/webpack-4/main.js
@@ -110,10 +110,12 @@
 /******/ 					if (event.type === 'load') {
 /******/ 						resolve();
 /******/ 					} else {
-/******/ 						var request = event && event.target && event.target.href || fullhref;
-/******/ 						var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 						var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 						var realHref = event && event.target && event.target.href || fullhref;
+/******/ 						var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 						err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 						err.request = request;
+/******/ 						err.type = errorType;
+/******/ 						err.request = realHref;
 /******/ 						delete installedCssChunks[chunkId]
 /******/ 						linkTag.parentNode.removeChild(linkTag)
 /******/ 						reject(err);
diff --git a/test/cases/insert-undefined/expected/webpack-5/main.js b/test/cases/insert-undefined/expected/webpack-5/main.js
index 5a4b5b2..a07e2a2 100644
--- a/test/cases/insert-undefined/expected/webpack-5/main.js
+++ b/test/cases/insert-undefined/expected/webpack-5/main.js
@@ -168,10 +168,12 @@
 /******/ 				if (event.type === 'load') {
 /******/ 					resolve();
 /******/ 				} else {
-/******/ 					var request = event && event.target && event.target.href || fullhref;
-/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
+/******/ 					var errorType = event && (event.type === 'load' ? 'missing' : event.type);
+/******/ 					var realHref = event && event.target && event.target.href || fullhref;
+/******/ 					var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + realHref + ")");
 /******/ 					err.code = "CSS_CHUNK_LOAD_FAILED";
-/******/ 					err.request = request;
+/******/ 					err.type = errorType;
+/******/ 					err.request = realHref;
 /******/ 					linkTag.parentNode.removeChild(linkTag)
 /******/ 					reject(err);
 /******/ 				}