UNPKG

967 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("[" + colors.symbols.cross + "]"),
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 if (this && this.emit) {
29 return this.emit("end", err);
30 }
31 } else {
32 process.exit(1);
33 }
34 };
35 return logError
36};