errorKey

tcmts.cli.main.errorKey · #mwa2fsis · term · runs anywhere

What errors alike have in common, to group them by: the first line of what was said, with the parts that differ from one to the next (numbers, ids, hashes, what's quoted) left out.

export function errorKey(error: string): string {
  return (
    (error.split("\n")[0] ?? "")
      // (a quote begins where no word does: "can't" isn't one)
      .replace(/(?<!\w)(["'`])[^"'`]*?\1(?!\w)/g, "$1…$1")
      .replace(/\b[0-9a-f]{8,}\b|\b[a-z2-7]{20,}\b/gi, "…")
      .replace(/\d+(?:\.\d+)?/g, "N")
      .slice(0, 200)
  );
}

used by