-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathpretty-error.js
44 lines (38 loc) · 1.13 KB
/
pretty-error.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* This file is part of the Symfony Webpack Encore package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
const PrettyError = require('pretty-error');
/**
* Render a pretty version of the given error.
*
* Supported options:
* - {function} skipTrace
* An optional callback that defines whether
* or not each line of the eventual stacktrace
* should be kept. First argument is the content
* of the line, second argument is the line number.
*
* @param {*} error
* @param {object} options
* @returns {void}
*/
module.exports = function(error, options = {}) {
const pe = new PrettyError();
// Use the default terminal's color
// for the error message.
pe.appendStyle({
'pretty-error > header > message': { color: 'none' }
});
// Allow to skip some parts of the
// stacktrace if there is one.
if (options.skipTrace) {
pe.skip(options.skipTrace);
}
console.log(pe.render(error));
};