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

fix(gatsby): show theme that has faulty config #27708

Merged
merged 4 commits into from Nov 2, 2020

Conversation

mxstbr
Copy link
Contributor

@mxstbr mxstbr commented Oct 29, 2020

When a user uses a theme that has a invalid plugin configuration in its gatsby-config.js, the user will see a blocking error:

❯ GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION=true yarn start
yarn run v1.22.4
$ gatsby develop

success open and validate gatsby-configs - 0.064s

 ERROR #11331  PLUGIN

Invalid plugin options for "gatsby-plugin-mdx":

- "plugins" must contain 0 items

not finished load plugins - 3.026s
error Command failed with exit code 1.

However, the user doesn't even have gatsby-plugin-mdx in their gatsby-config and cannot fix this since they might not have control over the theme that incorrectly uses this plugin! 😱

This patch fixes that case by instead 1) logging the directory of the faulty gatsby-config and 2) not blocking yarn develop if the error is from a gatsby-config outside the users root directory.

Now, it looks like this:

❯ GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION=true yarn start
yarn run v1.22.4
$ gatsby develop

Something is already running at port 8000
✔ Would you like to run the app at another port instead? … yes
success open and validate gatsby-configs - 0.073s
⠀
 ERROR #11331  PLUGIN

Invalid plugin options for "gatsby-plugin-mdx", configured by node_modules/@lekoarts/gatsby-theme-minimal-blog-core:

- "plugins" must contain 0 items

success load plugins - 0.892s
success onPreInit - 0.029s
success initialize cache - 0.026s
success copy gatsby files - 0.048s
success onPreBootstrap - 0.015s
success createSchemaCustomization - 0.010s
...etc...

This makes sure we don't block the user with errors they don't have control over.

@mxstbr mxstbr added the topic: cli Related to the Gatsby CLI label Oct 29, 2020
@mxstbr mxstbr requested a review from a team as a code owner October 29, 2020 07:42
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 29, 2020
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Oct 29, 2020
@wardpeet
Copy link
Contributor

Shouldn't we kill the process? If a theme has a bad config, the site will probably have funky behavior or error out eventually. I think it's best to die anyway

@mxstbr
Copy link
Contributor Author

mxstbr commented Oct 29, 2020

I don't think so, users literally cannot change it in most cases when they use a third-party theme. 🤔 I don't want to block anyone from using a theme even if it uses configuration that doesn't match the schema...

@wardpeet wardpeet changed the title fix(gatsby): show theme that has faulty config and do not block the users during option validation fix(gatsby): show theme that has faulty config Nov 2, 2020
@wardpeet wardpeet merged commit d7d1b97 into master Nov 2, 2020
@wardpeet wardpeet deleted the option-validation/add-plugin-parent-dir branch November 2, 2020 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: cli Related to the Gatsby CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants