Skip to content

Commit

Permalink
Add debug URL to all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jul 25, 2024
1 parent a9909e4 commit cbf2c73
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ function lexer(str: string) {
let pattern = "";

if (chars[i] === "?") {
throw new TypeError(`Pattern cannot start with "?" at ${i}`);
throw new TypeError(
`Pattern cannot start with "?" at ${i}: ${DEBUG_URL}`,
);
}

while (i < chars.length) {
Expand All @@ -204,15 +206,22 @@ function lexer(str: string) {
} else if (chars[i] === "(") {
count++;
if (chars[i + 1] !== "?") {
throw new TypeError(`Capturing groups are not allowed at ${i}`);
throw new TypeError(
`Capturing groups are not allowed at ${i}: ${DEBUG_URL}`,
);
}
}

pattern += chars[i++];
}

if (count) throw new TypeError(`Unbalanced pattern at ${pos}`);
if (!pattern) throw new TypeError(`Missing pattern at ${pos}`);
if (count) {
throw new TypeError(`Unbalanced pattern at ${pos}: ${DEBUG_URL}`);
}

if (!pattern) {
throw new TypeError(`Missing pattern at ${pos}: ${DEBUG_URL}`);
}

tokens.push({ type: "PATTERN", index: i, value: pattern });
continue;
Expand Down

0 comments on commit cbf2c73

Please sign in to comment.