WebpackError.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * @param {{ cause?: unknown }} options error options
  18. */
  19. constructor(message, options = {}) {
  20. super(message, options);
  21. /** @type {string=} */
  22. this.details = undefined;
  23. /** @type {(Module | null)=} */
  24. this.module = undefined;
  25. /** @type {DependencyLocation=} */
  26. this.loc = undefined;
  27. /** @type {boolean=} */
  28. this.hideStack = undefined;
  29. /** @type {Chunk=} */
  30. this.chunk = undefined;
  31. /** @type {string=} */
  32. this.file = undefined;
  33. }
  34. /**
  35. * @returns {string} inspect message
  36. */
  37. [inspect]() {
  38. return (
  39. this.stack +
  40. (this.details ? `\n${this.details}` : "") +
  41. (this.cause ? `\n${this.cause}` : "")
  42. );
  43. }
  44. /**
  45. * @param {ObjectSerializerContext} context context
  46. */
  47. serialize({ write }) {
  48. write(this.name);
  49. write(this.message);
  50. write(this.stack);
  51. write(this.cause);
  52. write(this.details);
  53. write(this.loc);
  54. write(this.hideStack);
  55. }
  56. /**
  57. * @param {ObjectDeserializerContext} context context
  58. */
  59. deserialize({ read }) {
  60. this.name = read();
  61. this.message = read();
  62. this.stack = read();
  63. this.cause = read();
  64. this.details = read();
  65. this.loc = read();
  66. this.hideStack = read();
  67. }
  68. }
  69. makeSerializable(WebpackError, "webpack/lib/WebpackError");
  70. /** @type {typeof WebpackError} */
  71. module.exports = WebpackError;