UNPKG

740 BJavaScriptView Raw
1'use strict';
2
3const stackTrace = require('stack-trace');
4
5module.exports = {
6 /**
7 * @returns {string} formatted stack trace for errors
8 * Evaluates every stack trace item and compose them together to make sure nothing important is missing
9 */
10 parseError: (e) => {
11 const error = stackTrace.parse(e);
12 let res = [];
13
14 res.push(`Error: ${e.message}`);
15
16 error.forEach((trace) => {
17 if (trace.fileName && trace.lineNumber && trace.columnNumber) {
18 const functionName = trace.functionName || '';
19 const struct = `\t at ${functionName} (${trace.fileName}:${trace.lineNumber}:${trace.columnNumber})`;
20 res.push(struct);
21 }
22 });
23
24 return res.join('\n');
25 }
26};