Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getCallerFileAndLineTag(): string {
const frame: StackTrace.StackFrame[] = StackTrace.parse(new Error());
let callerStackIndex = 1;
while (frame[callerStackIndex].getFileName().indexOf(path.basename(__filename)) >= 0) {
// go up the stack until we're outside of the BrightsideLogger file
callerStackIndex += 1;
}
const filename = path.basename(frame[callerStackIndex].getFileName());
const lineNumber = frame[callerStackIndex].getLineNumber();
return format("[%s:%s] ", filename, lineNumber);
}
function parseV8(error) {
assert.ok(error instanceof Error);
var parsed = stackTrace.parse(error);
return parsed.map(function(entry) {
var e = _.pick(entry, 'fileName', 'lineNumber', 'columnNumber', 'native');
// Flag entries that originated in eval'd webppl code. These will
// be looked up in the source map later.
e.webppl = entry.fileName === '';
// v8 column numbers are one indexed. Standardize on zero-based
// indexed as this is used by the source map library.
if (entry.columnNumber !== null) {
e.columnNumber = entry.columnNumber - 1;
}
e.name = null;
return e;
});
}
function findCallLocation(functionName: string): Location | undefined {
const stackTrace = parseStackTrace(new Error());
for (var i = 0; i < stackTrace.length - 1; i++) {
if (stackTrace[i].getFunctionName() === functionName) {
const callSite = stackTrace[i + 1];
return {
file: callSite.getFileName(),
line: callSite.getLineNumber() - 1
};
}
}
return undefined;
}
private stackTraceOf(error: Error): Array {
return parse(error).map((frame) => {
return {
declaringClass: frame.getTypeName() || frame.getFunctionName() || '',
methodName: frame.getMethodName() || frame.getFunctionName() || '',
fileName: frame.getFileName(),
lineNumber: frame.getLineNumber()
}
});
}
runner.on('fail', (test: Mocha.ITest, err: Error & { actual?: any, expected?: any, showDiff?: boolean }) => {
const testId = `${test.file}: ${test.fullTitle()}`;
const description = getElapsedTime(testId);
let decorations: TestDecoration[] = [];
if (err.stack) {
const parsedStack = stackTrace.parse(err);
for (const stackFrame of parsedStack) {
let filename = stackFrame.getFileName();
if (typeof filename === 'string') {
filename = path.resolve(filename);
let matchFound = false;
if (sloppyMatch && test.file) {
const f1 = filename.substring(0, filename.length - path.extname(filename).length);
const f2 = test.file.substring(0, test.file.length - path.extname(test.file).length);
if (f1 === f2) {
matchFound = true;
}
} else {
if (filename === test.file) {
matchFound = true;
}
}
export function callsite(logInfo: logform.TransformableInfo): logform.TransformableInfo {
const oldLimit = Error.stackTraceLimit;
try {
Error.stackTraceLimit = Infinity;
throw new Error();
} catch (e) {
const root = appRoot.path;
const callsites = trace.parse(e).map(l => ({
fileName: l.getFileName(),
lineNumber: l.getLineNumber(),
})).filter(cs => !!cs.fileName).reverse();
const callsite = callsites[callsites.findIndex(cs => cs.fileName.includes("node_modules/winston")) - 1];
if (!!callsite) {
return {
...logInfo,
callsite: {
...callsite,
fileName: callsite.fileName.split(root)[1].slice(1),
},
};
}
} finally {
Error.stackTraceLimit = oldLimit;
}
parseStackTrace(error) {
let callSites = StackTraceCache.get(error);
if (callSites) {
return callSites;
} else {
callSites = stackTrace.parse(error);
StackTraceCache.set(error, callSites);
return callSites;
}
}
function Error(error, errorClass) {
var callSites;
if (Utils.typeOf(error) === "string") {
this.message = error;
this.errorClass = errorClass || "Error";
} else if (error) {
this.message = error.message;
this.errorClass = errorClass || error.name || error.constructor.name || "Error";
} else {
this.message = "[unknown]";
this.errorClass = errorClass || "Error";
}
callSites = stacktrace.parse(error);
if (callSites.length === 0) {
callSites = stacktrace.get();
}
this.stacktrace = processCallSites(callSites, Configuration.projectRoot);
}
function filterStackTrace(filename, e) {
const lines = stackTrace.parse(e);
return lines
.filter(line => line.fileName === filename)
.map((line) => {
if (line.functionName) {
return `at ${line.functionName} (${line.fileName}:${line.lineNumber})`;
}
return `at ${line.fileName}:${line.lineNumber}`;
})
.join('\n');
}
utc: getUtc(utc),
name: err.name || 'Uncaught or API POST error',
step: err.step || null,
datasetId: err.datasetId || null,
requestTrace: err.requestTrace || null,
sessionTrace: err.sessionTrace || null,
sessionToken: err.sessionToken || null,
code: err.code || errCode,
version: version,
data: recs
};
if (!(process.env.NODE_ENV === 'test')) {
uploadErrProps.stringifiedStack = _.map(
_.filter(
stacktrace.parse(err),
(cs) => { return cs.functionName !== null; }
),
'functionName'
).join(', ');
}
return dispatch(syncActions.uploadFailure(displayErr, uploadErrProps, targetDevice));
}
const currentUpload = _.get(uploadsByUser, [uploadTargetUser, targetDevice.key], {});
dispatch(syncActions.uploadSuccess(uploadTargetUser, targetDevice, currentUpload, recs, utc));
};
}