errors.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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().render(err).replace(/webpack:\/\/\/\./g, context);
  29. } catch (e) {
  30. // This can sometimes fail. We don't know why, but returning the
  31. // original error is better than returning the error thrown by
  32. // pretty-error.
  33. return err;
  34. }
  35. }
  36. };
  37. };