How to use the stack-trace.parse function in stack-trace

To help you get started, we’ve selected a few stack-trace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zowe / imperative / packages / logger / src / Logger.ts View on Github external
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);
    }
github probmods / webppl / src / errors / parsers.js View on Github external
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;
  });
}
github hbenl / vscode-jasmine-test-adapter / src / worker / patchJasmine.ts View on Github external
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;
}
github jan-molak / serenity-js / lib / serenity / reporting / test_reports.ts View on Github external
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()
            }
        });
    }
github hbenl / vscode-mocha-test-adapter / src / worker / reporter.ts View on Github external
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;
								}
							}
github atomist / automation-client / lib / util / logger.ts View on Github external
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;
    }
github atom / atom / packages / exception-reporting / lib / reporter.js View on Github external
parseStackTrace(error) {
    let callSites = StackTraceCache.get(error);
    if (callSites) {
      return callSites;
    } else {
      callSites = stackTrace.parse(error);
      StackTraceCache.set(error, callSites);
      return callSites;
    }
  }
github bugsnag / bugsnag-node / lib / error.js View on Github external
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);
}
github globocom / functions / lib / domain / sandbox.js View on Github external
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');
}
github tidepool-org / uploader / app / actions / utils.js View on Github external
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));
  };
}

stack-trace

Get v8 stack traces as an array of CallSite objects.

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis

Popular stack-trace functions