-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
fix(core): throw error for invalid URL in config file #8192
fix(core): throw error for invalid URL in config file #8192
Conversation
* fix: throw error for site URL in sub-path format * Also update unit tests to check error is thrown
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Not ready to be merged yet
expect(() => | ||
normalizeConfig({ | ||
// This shouldn't happen | ||
url: 'https://mysite.com/foo/', | ||
}).url, | ||
).toBe('https://mysite.com/foo'); | ||
|
||
expect(consoleMock.mock.calls[0][0]).toMatchInlineSnapshot( | ||
`"[WARNING] Docusaurus config validation warning. Field "url": The url is not supposed to contain a sub-path like '/foo/'. Please use the baseUrl field for sub-paths."`, | ||
); | ||
}), | ||
).toThrowErrorMatchingInlineSnapshot(` | ||
"The url is not supposed to contain a sub-path like "". Please use the baseUrl field for sub-paths. | ||
" | ||
`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need this anymore, at least not in this test group, because here it's not testing URL normalization but URL rejection so this feels weird
helpers.warn('docusaurus.configValidationWarning', { | ||
warningMessage: `The url is not supposed to contain a sub-path like '${pathname}'. Please use the baseUrl field for sub-paths.`, | ||
}); | ||
return helpers.error('docusaurus.configValidationWarning'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use configValidationWarning
for something that is an error. Also pathname
used to be interpolated but it's not anymore
Unfortunately I can't really guide you to the correct solution: Joi is really a pain to do anything basic such as returning a custom error message 😅
…acebook#8192) * fix: throw custom error for site URL with sub-path * Also update unit test to check error is thrown
LGTM thanks 👍 |
Pre-flight checklist
Motivation
Currently, a warning is displayed when the URL contains a sub-path but as mentioned at the end of #8159, it makes more sense to display an error. So, I updated the code to display an error instead of a warning.
Test Plan
Test links
I updated unit tests to verify my code.
Related issues/PRs
Related to #8159 and #8116