WebpackError.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Jarid Margolin @jaridmargolin
  4. */
  5. "use strict";
  6. const inspect = require("util").inspect.custom;
  7. const makeSerializable = require("./util/makeSerializable");
  8. /** @typedef {import("./Chunk")} Chunk */
  9. /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
  10. /** @typedef {import("./Module")} Module */
  11. /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  12. /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  13. class WebpackError extends Error {
  14. /**
  15. * Creates an instance of WebpackError.
  16. * @param {string=} message error message
  17. */
  18. constructor(message) {
  19. super(message);
  20. /** @type {string=} */
  21. this.details = undefined;
  22. /** @type {(Module | null)=} */
  23. this.module = undefined;
  24. /** @type {DependencyLocation=} */
  25. this.loc = undefined;
  26. /** @type {boolean=} */
  27. this.hideStack = undefined;
  28. /** @type {Chunk=} */
  29. this.chunk = undefined;
  30. /** @type {string=} */
  31. this.file = undefined;
  32. }
  33. [inspect]() {
  34. return this.stack + (this.details ? `\n${this.details}` : "");
  35. }
  36. /**
  37. * @param {ObjectSerializerContext} context context
  38. */
  39. serialize({ write }) {
  40. write(this.name);
  41. write(this.message);
  42. write(this.stack);
  43. write(this.details);
  44. write(this.loc);
  45. write(this.hideStack);
  46. }
  47. /**
  48. * @param {ObjectDeserializerContext} context context
  49. */
  50. deserialize({ read }) {
  51. this.name = read();
  52. this.message = read();
  53. this.stack = read();
  54. this.details = read();
  55. this.loc = read();
  56. this.hideStack = read();
  57. }
  58. }
  59. makeSerializable(WebpackError, "webpack/lib/WebpackError");
  60. module.exports = WebpackError;