Skip to content

Commit 667d91f

Browse files
committed
Rename to PathError
1 parent 964404d commit 667d91f

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/index.spec.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
stringify,
77
pathToRegexp,
88
TokenData,
9-
ParseError,
9+
PathError,
1010
} from "./index.js";
1111
import {
1212
PARSER_TESTS,
@@ -21,7 +21,7 @@ import {
2121
describe("path-to-regexp", () => {
2222
describe("ParseError", () => {
2323
it("should contain original path and debug url", () => {
24-
const error = new ParseError(
24+
const error = new PathError(
2525
"Unexpected END at index 7, expected }",
2626
"/{:foo,",
2727
);
@@ -34,7 +34,7 @@ describe("path-to-regexp", () => {
3434
});
3535

3636
it("should omit original url when undefined", () => {
37-
const error = new ParseError(
37+
const error = new PathError(
3838
"Unexpected END at index 7, expected }",
3939
undefined,
4040
);
@@ -50,34 +50,31 @@ describe("path-to-regexp", () => {
5050
describe("parse errors", () => {
5151
it("should throw on unbalanced group", () => {
5252
expect(() => parse("/{:foo,")).toThrow(
53-
new ParseError("Unexpected END at index 7, expected }", "/{:foo,"),
53+
new PathError("Unexpected END at index 7, expected }", "/{:foo,"),
5454
);
5555
});
5656

5757
it("should throw on nested unbalanced group", () => {
5858
expect(() => parse("/{:foo/{x,y}")).toThrow(
59-
new ParseError(
60-
"Unexpected END at index 12, expected }",
61-
"/{:foo/{x,y}",
62-
),
59+
new PathError("Unexpected END at index 12, expected }", "/{:foo/{x,y}"),
6360
);
6461
});
6562

6663
it("should throw on missing param name", () => {
6764
expect(() => parse("/:/")).toThrow(
68-
new ParseError("Missing parameter name at index 2", "/:/"),
65+
new PathError("Missing parameter name at index 2", "/:/"),
6966
);
7067
});
7168

7269
it("should throw on missing wildcard name", () => {
7370
expect(() => parse("/*/")).toThrow(
74-
new ParseError("Missing parameter name at index 2", "/*/"),
71+
new PathError("Missing parameter name at index 2", "/*/"),
7572
);
7673
});
7774

7875
it("should throw on unterminated quote", () => {
7976
expect(() => parse('/:"foo')).toThrow(
80-
new ParseError("Unterminated quote at index 2", '/:"foo'),
77+
new PathError("Unterminated quote at index 2", '/:"foo'),
8178
);
8279
});
8380
});
@@ -127,7 +124,7 @@ describe("path-to-regexp", () => {
127124
describe("pathToRegexp errors", () => {
128125
it("should throw when missing text between params", () => {
129126
expect(() => pathToRegexp("/:foo:bar")).toThrow(
130-
new ParseError('Missing text before "bar" param', "/:foo:bar"),
127+
new PathError('Missing text before "bar" param', "/:foo:bar"),
131128
);
132129
});
133130

@@ -139,7 +136,7 @@ describe("path-to-regexp", () => {
139136
{ type: "param", name: "b" },
140137
]),
141138
),
142-
).toThrow(new ParseError('Missing text before "b" param', undefined));
139+
).toThrow(new PathError('Missing text before "b" param', undefined));
143140
});
144141

145142
it("should throw with `originalPath` when missing text between params using TokenData", () => {
@@ -153,7 +150,7 @@ describe("path-to-regexp", () => {
153150
"/[a][b]",
154151
),
155152
),
156-
).toThrow(new ParseError('Missing text before "b" param', "/[a][b]"));
153+
).toThrow(new PathError('Missing text before "b" param', "/[a][b]"));
157154
});
158155

159156
it("should contain the error line", () => {

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class TokenData {
171171
/**
172172
* ParseError is thrown when there is an error processing the path.
173173
*/
174-
export class ParseError extends TypeError {
174+
export class PathError extends TypeError {
175175
constructor(
176176
message: string,
177177
public readonly originalPath: string | undefined,
@@ -219,12 +219,12 @@ export function parse(str: string, options: ParseOptions = {}): TokenData {
219219
}
220220

221221
if (pos) {
222-
throw new ParseError(`Unterminated quote at index ${pos}`, str);
222+
throw new PathError(`Unterminated quote at index ${pos}`, str);
223223
}
224224
}
225225

226226
if (!value) {
227-
throw new ParseError(`Missing parameter name at index ${index}`, str);
227+
throw new PathError(`Missing parameter name at index ${index}`, str);
228228
}
229229

230230
return value;
@@ -292,7 +292,7 @@ export function parse(str: string, options: ParseOptions = {}): TokenData {
292292
continue;
293293
}
294294

295-
throw new ParseError(
295+
throw new PathError(
296296
`Unexpected ${type} at index ${index}, expected ${endType}`,
297297
str,
298298
);
@@ -562,7 +562,7 @@ function toRegExpSource(
562562

563563
if (token.type === "param" || token.type === "wildcard") {
564564
if (!isSafeSegmentParam && !backtrack) {
565-
throw new ParseError(
565+
throw new PathError(
566566
`Missing text before "${token.name}" ${token.type}`,
567567
originalPath,
568568
);

0 commit comments

Comments
 (0)