You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const WebpackError = require("./WebpackError");
  7. const { cutOffLoaderExecution } = require("./ErrorHelpers");
  8. class ModuleBuildError extends WebpackError {
  9. constructor(module, err, { from = null } = {}) {
  10. let message = "Module build failed";
  11. let details = undefined;
  12. if (from) {
  13. message += ` (from ${from}):\n`;
  14. } else {
  15. message += ": ";
  16. }
  17. if (err !== null && typeof err === "object") {
  18. if (typeof err.stack === "string" && err.stack) {
  19. const stack = cutOffLoaderExecution(err.stack);
  20. if (!err.hideStack) {
  21. message += stack;
  22. } else {
  23. details = stack;
  24. if (typeof err.message === "string" && err.message) {
  25. message += err.message;
  26. } else {
  27. message += err;
  28. }
  29. }
  30. } else if (typeof err.message === "string" && err.message) {
  31. message += err.message;
  32. } else {
  33. message += err;
  34. }
  35. } else {
  36. message = err;
  37. }
  38. super(message);
  39. this.name = "ModuleBuildError";
  40. this.details = details;
  41. this.module = module;
  42. this.error = err;
  43. Error.captureStackTrace(this, this.constructor);
  44. }
  45. }
  46. module.exports = ModuleBuildError;