export function prepareError()

in src/reporters/reporter-util.ts [108:143]


export function prepareError(error: Error) {
  const stack = error.stack;
  const lines = stack.split('\n');
  let startAt = lines.findIndex(line => line.startsWith('    at '));
  if (startAt === -1) {
    startAt = lines.length;
  }
  const message = lines.slice(0, startAt).join('\n');
  const stackLines = lines.slice(startAt);
  // figure out the location of the journey/step that throws the error and
  // correct stack line corresponding to that error
  const stackFrames: StackFrame[] = [];
  for (const line of stackLines) {
    const frame = prepareStackFrame(line);
    if (!frame || !frame.file) {
      continue;
    }
    stackFrames.push(frame);
  }

  let location: Location | undefined;
  if (stackFrames.length) {
    const frame = stackFrames[0];
    location = {
      file: frame.file,
      column: frame.column || 0,
      line: frame.line || 0,
    };
  }

  return {
    message,
    stack: constructStackFromFrames(stackFrames).join('\n'),
    location,
  };
}