UNPKG

881 BJavaScriptView Raw
1///@ts-check
2"use strict";
3var colors = require("ansi-colors");
4var log = require("./logger");
5const color = require("./color");
6
7/**
8 * @param {string} TITLE
9 */
10module.exports = function (TITLE) {
11 /**
12 * @param {Error} err
13 */
14 function logError(err) {
15 const skip = process.env.SKIP_ERROR;
16 log.error(
17 color(TITLE),
18 colors.bold.redBright("[×]"),
19 colors.red(err.name),
20 "\n",
21 colors.bgRed(err.message),
22 "\n",
23 //@ts-ignore
24 colors.red.underline(err.fileName||err.relativePath),
25 "\n" + (skip ? '' : err.stack ? (err.stack + '\n' + err) : JSON.stringify(err, null, 2).substring(0,2000))
26 );
27 if (skip) {
28 return this.emit("end", err);
29 } else {
30 process.exit(1);
31 }
32 };
33 return logError
34};