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

"Invalid context" error message is unhelpful when mixing paths with globs #964

Closed
2 tasks done
mcFrax opened this issue Jan 22, 2024 · 1 comment · Fixed by #987
Closed
2 tasks done

"Invalid context" error message is unhelpful when mixing paths with globs #964

mcFrax opened this issue Jan 22, 2024 · 1 comment · Fixed by #987

Comments

@mcFrax
Copy link

mcFrax commented Jan 22, 2024

Checks

Describe the bug (be clear and concise)

This message:

ERR_CONTEXT_MATCHER_INVALID_ARRAY = '[HPM] Invalid pathFilter. Expecting something like: ["/api", "/ajax"] or ["/api/**", "!**.html"]',

doesn't explain that mixing globs and non-globs is prohibited. Although it shows one array with just non-glob paths and one with globs, it doesn't clarify that these are examples of 2 separate categories of pathFilters.

I had to find the answer by Googling the error message and reading the code that produces it.

Step-by-step reproduction instructions

createProxyMiddleware(['/api/**', '/foo'], {
    target: "https://httpbin.org",
    changeOrigin: true,
  })

https://codesandbox.io/p/devbox/http-proxy-middleware-forked-6ky4n8?file=%2Fsrc%2Findex.js%3A10%2C5

Error message:

[HPM] Invalid pathFilter. Expecting something like: ["/api", "/ajax"] or ["/api/**", "!**.html"]
<stack trace>

Expected behavior (be clear and concise)

Error explaining that globs and paths cannot be mixed. Perhaps just this explanation added on top of the existing message.

[HPM] Invalid pathFilter. Expecting something like: ["/api", "/ajax"] or ["/api/**", "!**.html"]. Plain paths (e.g. "/api") can't be mixed with globs (e.g. "/api/**").

How is http-proxy-middleware used in your project?

Indirectly, with Webpack's devServer.

What http-proxy-middleware configuration are you using?

[irrelevant]

What OS/version and node/version are you seeing the problem?

[irrelevant]

Additional context (optional)

The error is thrown in this line.

The only cases handled for array are pathFilter.every(isStringPath) and pathFilter.every(isGlobPath). isStringPath checks that the string is not a glob - so for mixed paths and globs neither of the conditions will be fullfilled.

@chimurai
Copy link
Owner

chimurai commented Apr 6, 2024

Hi @mcFrax

Thanks for suggestion. Sounds like a good improvement.

Care to create a PR with your suggestion to improve the error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants