mobile-dev-environment
Version:
Stuck in a browser with primitive dev features? Include this in your web app for a basic set of useful features.
21 lines (20 loc) • 691 B
JavaScript
// Provide an error and retrieve trace information
module.exports = function tracer(error, type) {
// Get stack as string
let stack = error.stack;
// Get last line of stack
stack = stack.split("\n")[stack.split("\n").length-1];
// Break stack into pieces of information
const pieces = stack.split(":");
// Get line number
const lineNumber = pieces[3];
// Get file path
const filePath = (pieces[0].split('at ').join('') + ':' + pieces[1]).replace(/ /g, '');
// Get file name
const fileName = filePath.replace(/^.*[\\\/]/, '');
return {
fileName: fileName.length > 0 ? fileName : 'N/A',
filePath,
lineNumber
};
}