Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setDecoration(status, test) {
if (config.sideBarOptions().decoration) {
let style = this.getStyle(status);
// console.log(`test file in decorations: ${test.item.__test.file}, name:${test.item.__test.name}`);
if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document.fileName == test.file) {
let decorators = {
range: new vscode.Range(test.meta.number - 1, 0, test.meta.number - 1, 1e3),
hoverMessage: new vscode.MarkdownString("#### " + status)
//range: new vscode.Range(line[0].number - 1, it.start.column - 1, line[0].number - 1, it.start.column + 1)
};
try {
//stub
if (status == consts.FAILED) {
const stacktrace = stacktraceParser.parse(test.error.raw.stack);
if (stacktrace && stacktrace[0] && stacktrace[0].lineNumber) {
let errorMessageDecorator = {
range: new vscode.Range(stacktrace[0].lineNumber - 1, 0, stacktrace[0].lineNumber - 1, 1e3),
hoverMessage: new vscode.MarkdownString(`#### Stack trace
\`\`\`javascript
${test.error.raw.stack}
\`\`\` `)
};
let errorMessageStyle = decorationType.expectErrorMessage(test.error.raw.message);
this.pushStyle.push(errorMessageStyle);
vscode.window.activeTextEditor.setDecorations(errorMessageStyle, [errorMessageDecorator]);
}
}
function renderStack(e) {
var st = StackTraceParser.parse(e.stack)[0];
var parts = __dirname.split("/");
var parent = parts.slice(0, parts.length-1).join("/")
var fn = st.file.replace(parent + "/", "");
return `${e.message}, ${fn}:${st.lineNumber}`;
}
const NICE_ERRORS = {
this.stream.on('generror', function (e) {
//find the line of a code
var stack = parseStack(e.stack);
var evalOffset = 2;
var message = e.message + ' at ' + (stack[0].lineNumber - evalOffset) + ':' + stack[0].column;
error.value = message;
});
backtrace(stack='') {
return parse(stack).map((entry) => {
return {
file: entry.file,
line: entry.lineNumber,
column: entry.column,
function: entry.methodName
};
});
},
Retrace.prototype.map = function(stack) {
return Promise.all(parser.parse(stack).map(this.mapFrame, this))
.then(function(frames) {
var msg = /^.*$/m.exec(stack)[0];
return msg + '\n' + frames.map(function(f) {
var pos = f.source;
if (f.line) pos += ':' + f.line;
if (f.column >= 0) pos += ':' + f.column;
var loc = f.name ? f.name + '(' + pos + ')' : pos;
return ' at ' + loc;
}).join('\n');
});
};
function parseErrorStack(e) {
if (!e || !e.stack) {
return [];
}
const stacktraceParser = require('stacktrace-parser');
const stack = Array.isArray(e.stack)
? e.stack
: stacktraceParser.parse(e.stack);
let framesToPop = typeof e.framesToPop === 'number' ? e.framesToPop : 0;
while (framesToPop--) {
stack.shift();
}
return stack;
}
const parseErrorStack = error => {
if (!error || !error.stack) {
return [];
}
return Array.isArray(error.stack)
? error.stack
: stacktraceParser.parse(error.stack);
};
getStackTraceData(stackTrace) {
const stack = stackTraceParser.parse(stackTrace)
const newSourceMap = []
for(const trace of stack) {
const sourceMapData = this.sourceMaps.find((sourceMapData) => sourceMapData.originalUrl == trace.file)
let filePath, fileString, original
if (sourceMapData) {
const sourceMapConsumer = sourceMapData.consumer
original = sourceMapConsumer.originalPositionFor({
line: trace.lineNumber,
column: trace.column
})
}
if (original && original.source) {
filePath = original.source.replace(/^webpack:\/\/\//, "")