Skip to content

Clarify the link included in parser error messages #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ describe("path-to-regexp", () => {
it("should throw on unbalanced group", () => {
expect(() => parse("/{:foo,")).toThrow(
new TypeError(
"Unexpected END at 7, expected }: https://git.new/pathToRegexpError",
"Unexpected END at 7, expected }: visit https://git.new/pathToRegexpError for more information.",
),
);
});
it("should throw on nested unbalanced group", () => {
expect(() => parse("/{:foo/{x,y}")).toThrow(
new TypeError(
"Unexpected END at 12, expected }: https://git.new/pathToRegexpError",
"Unexpected END at 12, expected }: visit https://git.new/pathToRegexpError for more information.",
),
);
});

it("should throw on missing param name", () => {
expect(() => parse("/:/")).toThrow(
new TypeError(
"Missing parameter name at 2: https://git.new/pathToRegexpError",
"Missing parameter name at 2: visit https://git.new/pathToRegexpError for more information.",
),
);
});

it("should throw on missing wildcard name", () => {
expect(() => parse("/*/")).toThrow(
new TypeError(
"Missing parameter name at 2: https://git.new/pathToRegexpError",
"Missing parameter name at 2: visit https://git.new/pathToRegexpError for more information.",
),
);
});

it("should throw on unterminated quote", () => {
expect(() => parse('/:"foo')).toThrow(
new TypeError(
"Unterminated quote at 2: https://git.new/pathToRegexpError",
"Unterminated quote at 2: visit https://git.new/pathToRegexpError for more information.",
),
);
});
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ function* lexer(str: string): Generator<LexToken, LexToken> {
}

if (pos) {
throw new TypeError(`Unterminated quote at ${pos}: ${DEBUG_URL}`);
throw new TypeError(
`Unterminated quote at ${pos}: visit ${DEBUG_URL} for more information.`,
);
}
}

if (!value) {
throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);
throw new TypeError(
`Missing parameter name at ${i}: visit ${DEBUG_URL} for more information.`,
);
}

return value;
Expand Down Expand Up @@ -203,7 +207,7 @@ class Iter {
if (value !== undefined) return value;
const { type: nextType, index } = this.peek();
throw new TypeError(
`Unexpected ${nextType} at ${index}, expected ${type}: ${DEBUG_URL}`,
`Unexpected ${nextType} at ${index}, expected ${type}: visit ${DEBUG_URL} for more information.`,
);
}

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

if (token.type === "param" || token.type === "wildcard") {
if (!isSafeSegmentParam && !backtrack) {
throw new TypeError(`Missing text after "${token.name}": ${DEBUG_URL}`);
throw new TypeError(
`Missing text after "${token.name}": visit ${DEBUG_URL} for more information.`,
);
}

if (token.type === "param") {
Expand Down