Skip to content

Commit 73e50d1

Browse files
committed
Clarify the link included in parser error messages
1 parent f4f51b7 commit 73e50d1

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/index.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@ describe("path-to-regexp", () => {
1515
it("should throw on unbalanced group", () => {
1616
expect(() => parse("/{:foo,")).toThrow(
1717
new TypeError(
18-
"Unexpected END at 7, expected }: https://git.new/pathToRegexpError",
18+
"Unexpected END at 7, expected }: visit https://git.new/pathToRegexpError for more information.",
1919
),
2020
);
2121
});
2222
it("should throw on nested unbalanced group", () => {
2323
expect(() => parse("/{:foo/{x,y}")).toThrow(
2424
new TypeError(
25-
"Unexpected END at 12, expected }: https://git.new/pathToRegexpError",
25+
"Unexpected END at 12, expected }: visit https://git.new/pathToRegexpError for more information.",
2626
),
2727
);
2828
});
2929

3030
it("should throw on missing param name", () => {
3131
expect(() => parse("/:/")).toThrow(
3232
new TypeError(
33-
"Missing parameter name at 2: https://git.new/pathToRegexpError",
33+
"Missing parameter name at 2: visit https://git.new/pathToRegexpError for more information.",
3434
),
3535
);
3636
});
3737

3838
it("should throw on missing wildcard name", () => {
3939
expect(() => parse("/*/")).toThrow(
4040
new TypeError(
41-
"Missing parameter name at 2: https://git.new/pathToRegexpError",
41+
"Missing parameter name at 2: visit https://git.new/pathToRegexpError for more information.",
4242
),
4343
);
4444
});
4545

4646
it("should throw on unterminated quote", () => {
4747
expect(() => parse('/:"foo')).toThrow(
4848
new TypeError(
49-
"Unterminated quote at 2: https://git.new/pathToRegexpError",
49+
"Unterminated quote at 2: visit https://git.new/pathToRegexpError for more information.",
5050
),
5151
);
5252
});

src/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ function* lexer(str: string): Generator<LexToken, LexToken> {
145145
}
146146

147147
if (pos) {
148-
throw new TypeError(`Unterminated quote at ${pos}: ${DEBUG_URL}`);
148+
throw new TypeError(
149+
`Unterminated quote at ${pos}: visit ${DEBUG_URL} for more information.`,
150+
);
149151
}
150152
}
151153

152154
if (!value) {
153-
throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);
155+
throw new TypeError(
156+
`Missing parameter name at ${i}: visit ${DEBUG_URL} for more information.`,
157+
);
154158
}
155159

156160
return value;
@@ -203,7 +207,7 @@ class Iter {
203207
if (value !== undefined) return value;
204208
const { type: nextType, index } = this.peek();
205209
throw new TypeError(
206-
`Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`,
210+
`Unexpected ${nextType} at ${index}, expected ${type}: visit ${DEBUG_URL} for more information.`,
207211
);
208212
}
209213

@@ -575,7 +579,9 @@ function toRegExp(tokens: Flattened[], delimiter: string, keys: Keys) {
575579

576580
if (token.type === "param" || token.type === "wildcard") {
577581
if (!isSafeSegmentParam && !backtrack) {
578-
throw new TypeError(`Missing text after "${token.name}": ${DEBUG_URL}`);
582+
throw new TypeError(
583+
`Missing text after "${token.name}": visit ${DEBUG_URL} for more information.`,
584+
);
579585
}
580586

581587
if (token.type === "param") {

0 commit comments

Comments
 (0)