Skip to content

Commit 2962bc0

Browse files
committed
Update error message
1 parent 98246be commit 2962bc0

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/index.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ describe("path-to-regexp", () => {
2222
it("should throw on unbalanced group", () => {
2323
expect(() => parse("/{:foo,")).toThrow(
2424
new TypeError(
25-
"Unexpected END at index 7, expected }: /{:foo,; visit https://git.new/pathToRegexpError for more info",
25+
"Unexpected END at index 7, expected }: /{:foo,; visit https://git.new/pathToRegexpError for info",
2626
),
2727
);
2828
});
2929

3030
it("should throw on nested unbalanced group", () => {
3131
expect(() => parse("/{:foo/{x,y}")).toThrow(
3232
new TypeError(
33-
"Unexpected END at index 12, expected }: /{:foo/{x,y}; visit https://git.new/pathToRegexpError for more info",
33+
"Unexpected END at index 12, expected }: /{:foo/{x,y}; visit https://git.new/pathToRegexpError for info",
3434
),
3535
);
3636
});
3737

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

4646
it("should throw on missing wildcard name", () => {
4747
expect(() => parse("/*/")).toThrow(
4848
new TypeError(
49-
"Missing parameter name at index 2: /*/; visit https://git.new/pathToRegexpError for more info",
49+
"Missing parameter name at index 2: /*/; visit https://git.new/pathToRegexpError for info",
5050
),
5151
);
5252
});
5353

5454
it("should throw on unterminated quote", () => {
5555
expect(() => parse('/:"foo')).toThrow(
5656
new TypeError(
57-
'Unterminated quote at index 2: /:"foo; visit https://git.new/pathToRegexpError for more info',
57+
'Unterminated quote at index 2: /:"foo; visit https://git.new/pathToRegexpError for info',
5858
),
5959
);
6060
});
@@ -106,7 +106,7 @@ describe("path-to-regexp", () => {
106106
it("should throw when missing text between params", () => {
107107
expect(() => pathToRegexp("/:foo:bar")).toThrow(
108108
new TypeError(
109-
'Missing text before "bar": /:foo:bar; visit https://git.new/pathToRegexpError for more info',
109+
'Missing text before "bar": /:foo:bar; visit https://git.new/pathToRegexpError for info',
110110
),
111111
);
112112
});
@@ -121,7 +121,7 @@ describe("path-to-regexp", () => {
121121
),
122122
).toThrow(
123123
new TypeError(
124-
'Missing text before "b"; visit https://git.new/pathToRegexpError for more info',
124+
'Missing text before "b"; visit https://git.new/pathToRegexpError for info',
125125
),
126126
);
127127
});
@@ -139,7 +139,7 @@ describe("path-to-regexp", () => {
139139
),
140140
).toThrow(
141141
new TypeError(
142-
'Missing text before "b": /[a][b]; visit https://git.new/pathToRegexpError for more info',
142+
'Missing text before "b": /[a][b]; visit https://git.new/pathToRegexpError for info',
143143
),
144144
);
145145
});

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ function escape(str: string) {
115115
/**
116116
* Format error so it's easier to debug.
117117
*/
118-
function errorMessage(message: string, originalPath: string | undefined) {
119-
if (originalPath) {
120-
return `${message}: ${originalPath}; visit ${DEBUG_URL} for more info`;
121-
}
122-
return `${message}; visit ${DEBUG_URL} for more info`;
118+
function errorMessage(text: string, originalPath: string | undefined) {
119+
let message = text;
120+
if (originalPath !== undefined) message += `: ${originalPath}`;
121+
message += `; visit ${DEBUG_URL} for info`;
122+
return message;
123123
}
124124

125125
/**

0 commit comments

Comments
 (0)