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

Improve error messages of createPage API #3357

Closed
arku opened this issue Dec 28, 2017 · 7 comments
Closed

Improve error messages of createPage API #3357

arku opened this issue Dec 28, 2017 · 7 comments
Labels
good first issue Issue that doesn't require previous experience with Gatsby

Comments

@arku
Copy link
Contributor

arku commented Dec 28, 2017

While experimenting with gatsby by making a simple portfolio site, I made a mistake of not supplying component property to the object passed to createPage function 🙈
This is what I made my code looked like:

const path = require('path')

exports.createPages = ({ boundActionCreators, graphql }) => {
  const { createPage } = boundActionCreators
  const blogPostTemplate = path.resolve('src/templates/blogPost.js')

  return graphql(`
    {
      allMarkdownRemark {
        edges {
          node {
            html
            frontmatter {
              title
              date
              path
              excerpt
            }
          }
        }
      }
    }
  `).then(result => {
      if (result.errors) {
        return Promise.reject(result.errors)
      }

      const { edges: posts } = result.data.allMarkdownRemark
      posts.forEach(({ node: post }) => {
        const { path } = post.frontmatter
        createPage({
          path,
          template: blogPostTemplate  // should be `component: blogPostTemplate`
        })
      })
  })
}

At that time, I didn't realize the error and was struggling to understand what was going on. The error message I got during the build process looked like:

TypeError: Path must be a string. Received undefined

The above error message is useful but it does not clearly highlight what I was missing.

To maintainers:

What do you think about throwing an error message which reads along the lines of:

Missing required property `component`: Looks like you haven't passed a `component` property to `createPage` function.

We could point the user to the line number of the createPage function invocation.

Note: The above request is not a priority and an enhancement. I'll let you guys decide if it is worth working on it.

@calcsam
Copy link
Contributor

calcsam commented Jan 14, 2018

Great idea! Probably the best approach here would be to add schema validation in Joi -- possibly only in dev mode? -- for inputs on the createPage function: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/redux/actions.js

eg

https://github.com/hapijs/joi/blob/master/examples/customMessage.js

Re priority, we're heavily into making Gatsby an awesome experience! we'd love a PRs on this @arun1595 or anyone else who is interested

@KyleAMathews KyleAMathews added the good first issue Issue that doesn't require previous experience with Gatsby label Jan 15, 2018
@GregBorrelly
Copy link
Contributor

@calcsam I would like to work on this issue.

@calcsam
Copy link
Contributor

calcsam commented Jan 26, 2018

@GregBorrelly it's yours -- i'll add you to the core team (check your email in the morning) and assign it to you!

@calcsam
Copy link
Contributor

calcsam commented Jan 26, 2018

@GregBorrelly thanks for taking this on!

@GregBorrelly
Copy link
Contributor

Thank you @calcsam !!!!

@fk fk added the DX label Jan 26, 2018
@GregBorrelly
Copy link
Contributor

GregBorrelly commented Jan 30, 2018

@calcsam Status update: working on the issue, I got stuck migrating an app at work so that took a while.

@KyleAMathews
Copy link
Contributor

Oh actually did a PR for this already 😅 forgot to close out this issue. @GregBorrelly can you upgrade to master and tell me what you think about the new error handling? #3773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby
Projects
None yet
Development

No branches or pull requests

5 participants