ModuleError.js 843 B

123456789101112131415161718192021222324252627282930313233343536
  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 { cleanUp } = require("./ErrorHelpers");
  8. class ModuleError extends WebpackError {
  9. constructor(module, err, { from = null } = {}) {
  10. let message = "Module Error";
  11. if (from) {
  12. message += ` (from ${from}):\n`;
  13. } else {
  14. message += ": ";
  15. }
  16. if (err && typeof err === "object" && err.message) {
  17. message += err.message;
  18. } else if (err) {
  19. message += err;
  20. }
  21. super(message);
  22. this.name = "ModuleError";
  23. this.module = module;
  24. this.error = err;
  25. this.details =
  26. err && typeof err === "object" && err.stack
  27. ? cleanUp(err.stack, this.message)
  28. : undefined;
  29. Error.captureStackTrace(this, this.constructor);
  30. }
  31. }
  32. module.exports = ModuleError;