errors.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // @ts-nocheck
  2. "use strict";
  3. let prettyError;
  4. function getPrettyError() {
  5. if (!prettyError) {
  6. // lazily require to improve startup time since pretty-error is rather heavy package
  7. const PrettyError = require("pretty-error");
  8. prettyError = new PrettyError();
  9. prettyError.withoutColors();
  10. prettyError.skipPackage("html-plugin-evaluation");
  11. prettyError.skipNodeFiles();
  12. prettyError.skip(function (traceLine) {
  13. return traceLine.path === "html-plugin-evaluation";
  14. });
  15. }
  16. return prettyError;
  17. }
  18. module.exports = function (err, context) {
  19. return {
  20. toHtml: function () {
  21. return "Html Webpack Plugin:\n<pre>\n" + this.toString() + "</pre>";
  22. },
  23. toJsonHtml: function () {
  24. return JSON.stringify(this.toHtml());
  25. },
  26. toString: function () {
  27. try {
  28. return getPrettyError()
  29. .render(err)
  30. .replace(/webpack:\/\/\/\./g, context);
  31. } catch (e) {
  32. // This can sometimes fail. We don't know why, but returning the
  33. // original error is better than returning the error thrown by
  34. // pretty-error.
  35. return err;
  36. }
  37. },
  38. };
  39. };