WebpackError.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. [inspect]() {
  35. return (
  36. this.stack +
  37. (this.details ? `\n${this.details}` : "") +
  38. (this.cause ? `\n${this.cause}` : "")
  39. );
  40. }
  41. /**
  42. * @param {ObjectSerializerContext} context context
  43. */
  44. serialize({ write }) {
  45. write(this.name);
  46. write(this.message);
  47. write(this.stack);
  48. write(this.cause);
  49. write(this.details);
  50. write(this.loc);
  51. write(this.hideStack);
  52. }
  53. /**
  54. * @param {ObjectDeserializerContext} context context
  55. */
  56. deserialize({ read }) {
  57. this.name = read();
  58. this.message = read();
  59. this.stack = read();
  60. this.cause = read();
  61. this.details = read();
  62. this.loc = read();
  63. this.hideStack = read();
  64. }
  65. }
  66. makeSerializable(WebpackError, "webpack/lib/WebpackError");
  67. module.exports = WebpackError;