Skip to content
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

docs: more detailed error message when failing to parse a middleware matcher #41390

Merged
merged 5 commits into from Oct 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion errors/invalid-route-source.md
Expand Up @@ -2,12 +2,18 @@

#### Why This Error Occurred

When defining custom routes a route was added that causes an error during parsing. This can be due to trying to use normal `RegExp` syntax like negative lookaheads (`?!exclude`) without following `path-to-regexp`'s syntax for it.
When defining custom routes, or a middleware matcher, a pattern can not be parsed.
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved

This can be due to trying to use normal `RegExp` syntax like negative lookaheads (`?!exclude`) without following `path-to-regexp`'s syntax for it.
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved

#### Possible Ways to Fix It

Wrap the `RegExp` part of your `source` as an un-named parameter.

---

Custom routes:

**Before**

```js
Expand All @@ -26,6 +32,26 @@ Wrap the `RegExp` part of your `source` as an un-named parameter.
}
```

---

Middleware:

**Before**

```js
const config = {
matcher: '/feedback/(?!general)',
}
```

**After**

```js
const config = {
matcher: '/feedback/((?!general).*)',
}
```

### Useful Links

- [path-to-regexp](https://github.com/pillarjs/path-to-regexp)
Expand Down