# All files / src/utils generate-error.js

100% Statements 8/8
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35

    26x
    26x
    26x
    26x
    1x

    25x

    26x
    26x

     // @flow

    export default function generateErrorString(
      msg: string,
      error: string,
      marker: {
        start: { sourceLine: string, line: number, col: number },
        end: { sourceLine: string, line: number, col: number },
      },
      filename: string,
      func: string
    ): string {
      const { line, col } = marker.start;
      const { col: end } = marker.end;
      const Line = (() => {
        if (marker.start.sourceLine !== marker.end.sourceLine) {
          return marker.start.sourceLine + "\n" + marker.end.sourceLine;
        }
        return marker.end.sourceLine;
      })();

      const highlight = new Array(end - col + 1).join("^").padStart(end, " ");
      return (
        "\n" +
        Line +
        "\n" +
        highlight +
        ` ${error}` +
        "\n" +
        msg +
        "\n" +
        `  at ${func} (${filename}:${line}:${col})`
      );
    }