How to use error-stack-parser - 10 common examples

To help you get started, we’ve selected a few error-stack-parser 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 DevExpress / testcafe / test / server / helpers / assert-runtime-error.js View on Github external
function assertStack (err, expected) {
    // HACK: stackParser can't handle empty stacks correctly
    // (it treats error messages as stack frames).
    // Therefore we add this dummy stack frame to make things work
    if (!expected.stackTop)
        err.stack += '\n    at (:1:1)';

    const parsedStack = stackParser.parse(err);

    if (expected.stackTop) {
        const expectedStackTop = Array.isArray(expected.stackTop) ? expected.stackTop : [expected.stackTop];

        parsedStack.forEach(function (frame, idx) {
            const filename   = frame.fileName;
            const isInternal = frame.fileName.indexOf('internal/') === 0 ||
                               frame.fileName.indexOf(sep) < 0;

            // NOTE: assert that stack is clean from internals
            expect(isInternal).to.be.false;
            expect(filename).not.to.contain(sep + 'babel-');
            expect(filename).not.to.contain(sep + 'babylon' + sep);
            expect(filename).not.to.contain(sep + 'core-js' + sep);

            if (expectedStackTop[idx])
github iodide-project / iodide / src / reps / serialization / get-error-stack-summary.js View on Github external
export function getErrorStackString(e) {
  // Handle passing in an Array of pre-parsed frames for testing
  const frames = e instanceof Array ? e : ErrorStackParser.parse(e);
  const outputFrames = [];

  for (const frame of frames) {
    if (frame.fileName !== undefined) {
      const parts = frame.fileName.split("/");
      if (parts[parts.length - 1].startsWith("iodide.eval-frame")) {
        break;
      }
    }
    outputFrames.push(frame.toString());
  }

  return `${e.name}: ${e.message}\n${outputFrames.join("\n")}`;
}
github iodide-project / iodide / src / reps / serialization / get-error-stack-summary.js View on Github external
lineNumber: evalLocationParts[1],
          columnNumber: evalLocationParts[2],
          source: line,
          isEval: true
        });
      }
    }

    if (line.indexOf("@") === -1 && line.indexOf(":") === -1) {
      // Safari eval frames only have function names and nothing else
      return new StackFrame({
        functionName: line
      });
    }

    const locationParts = ErrorStackParser.extractLocation(
      line.replace(functionNameRegex, "")
    );

    return new StackFrame({
      functionName,
      fileName: locationParts[0],
      lineNumber: locationParts[1],
      columnNumber: locationParts[2],
      source: line
    });
  }, ErrorStackParser);
};
github iodide-project / iodide / src / reps / serialization / get-error-stack-summary.js View on Github external
return filtered.map(line => {
    const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
    const matches = line.match(functionNameRegex);
    const functionName = matches && matches[1] ? matches[1] : undefined;

    if (line.indexOf(" > eval") > -1) {
      const regExp = / > (eval:\d+:\d+)$/;
      const evalParts = regExp.exec(line);
      if (evalParts) {
        const evalLocationParts = ErrorStackParser.extractLocation(
          evalParts[1]
        );
        return new StackFrame({
          functionName: functionName !== undefined ? functionName : "eval",
          fileName: "cell",
          lineNumber: evalLocationParts[1],
          columnNumber: evalLocationParts[2],
          source: line,
          isEval: true
        });
      }
    }

    if (line.indexOf("@") === -1 && line.indexOf(":") === -1) {
      // Safari eval frames only have function names and nothing else
      return new StackFrame({
github recca0120 / tester-phpunit / lib / mocha-runner.js View on Github external
const pushTestResult = function pushTestResult(test) {
      console.log('++++pushTestResult', test);
      console.log('++++pushTestResult _trace', test._trace);
      if (!test || !test._trace) {
        console.log('++++test trace is empty', test);
        return;
      }
      const traceObjects = ErrorStackParser.parse(test._trace)
        .filter(stackTraceObject => stackTraceObject.fileName === outputFilePath);
      console.log('++++traceObjects', traceObjects);
      const traceObject = traceObjects.length > 0 ? traceObjects[0] : traceObjects;
      if (!traceObject) {
        console.log('++++traceObject is empty', test);
        return;
      }

      console.log('++++trace', traceObject);
      if (!test.state) {
        test.state = 'skipped';
      }
      messages.push({
        state: test.state,
        title: test.title,
        error: test.err,
github invertase / react-native-firebase / tests-new / bridge / env / node / source-map.js View on Github external
function sourceMappedError(error) {
  const original = error.stack.split('\n');
  const parsed = ErrorStack.parse(error);

  const newStack = [original[0]];

  for (let i = 0; i < parsed.length; i++) {
    const { fileName } = parsed[i];
    if (fileName === bundleFileName) newStack.push(frameToStr(parsed[i]));
    else newStack.push(original[i + 1]);
  }

  error.stack = newStack.join('\n');
  return error;
}
github aulizko / delicate-error-reporter / src / index.js View on Github external
renderFrames() {
    console.log('error', this.props.error);
    console.log('parsed error', ErrorStackParser.parse(this.props.error));
    return ErrorStackParser.parse(this.props.error).map((f) => {
      const link = `${ f.fileName }:${ f.lineNumber }:${ f.columnNumber }`;

      return (
        <div>
          <div>{ f.functionName }</div>
          <div>
            <a href="{">{ link }</a>
          </div>
        </div>
      );
    });
  }
github iodide-project / iodide / src / reps / serialization / get-error-stack-summary.js View on Github external
const fileName =
      ["eval", ""].indexOf(locationParts[0]) &gt; -1
        ? undefined
        : locationParts[0];

    return new StackFrame({
      functionName,
      fileName,
      lineNumber: locationParts[1],
      columnNumber: locationParts[2],
      source: line
    });
  }, ErrorStackParser);
};

ErrorStackParser.parseFFOrSafari = error =&gt; {
  const filtered = error.stack
    .split("\n")
    .filter(
      line =&gt; !line.match(/^(eval@)?(\[native code\])?$/),
      ErrorStackParser
    );

  return filtered.map(line =&gt; {
    const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
    const matches = line.match(functionNameRegex);
    const functionName = matches &amp;&amp; matches[1] ? matches[1] : undefined;

    if (line.indexOf(" &gt; eval") &gt; -1) {
      const regExp = / &gt; (eval:\d+:\d+)$/;
      const evalParts = regExp.exec(line);
      if (evalParts) {
github iodide-project / iodide / src / reps / serialization / get-error-stack-summary.js View on Github external
import ErrorStackParser from "error-stack-parser";
import StackFrame from "stackframe";

ErrorStackParser.parseV8OrIE = error =&gt; {
  const filtered = error.stack
    .split("\n")
    .filter(
      line =&gt; !!line.match(/^\s*at .*(\S+:\d+|\(native\))/m),
      ErrorStackParser
    );

  return filtered.map(line =&gt; {
    const tokens = line
      .replace(/^\s+/, "")
      .replace(/\(eval code/g, "(")
      .split(/\s+/)
      .slice(1);

    if (line.indexOf("(eval ") &gt; -1) {
      const regExp = /\), (&lt;[^&gt;]+&gt;:\d+:\d+)\)$/;
github thealjey / webcompiler / src / logger.js View on Github external
export function logError(error: Error) {
  const {name, message, stack} = error;

  log(formatErrorMarker(name), ': ', message);

  error.stack = cleanStack(stack);

  forEach(ErrorStackParser.parse(error), ({functionName = 'unknown', fileName, lineNumber, columnNumber}) => {
    log('  • ', ...formatLine(functionName, fileName, lineNumber, columnNumber));
  });
}

error-stack-parser

Extract meaning from JS Errors

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis