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

Adds error message with filename on Markdown error, fixes bug in panicOnBuild #8866

Merged
merged 5 commits into from
Oct 9, 2018
Merged

Adds error message with filename on Markdown error, fixes bug in panicOnBuild #8866

merged 5 commits into from
Oct 9, 2018

Conversation

mslooten
Copy link
Contributor

@mslooten mslooten commented Oct 6, 2018

As discussed in #8524, when Markdown isn't correctly processed an error is thrown which doesn't include the filename. This fixes it using a try/catch with the reporter.panicOnBuild function, which is also changed since it had unexpected behavior (it didn't terminate the build, but it did terminate on other commands such as gatsby develop).

---edit by @pieh:
closes #8524

@mslooten mslooten requested a review from a team as a code owner October 6, 2018 09:19
createParentChildLink({ parent: node, child: markdownNode })
} catch (err) {
reporter.panicOnBuild(
`Error processing Markdown file ${node.absolutePath}:\n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about something earlier - markdown doesn't always come from file, so we will need to check if node.absolutePath is set before using it. For example:

`Error processing Markdown ${node.absolutePath ? `file: ${node.absolutePath}` : ``}:\n`

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, only one last small thing to fix (my bad for not thinking about it earlier when I left some comments in the issue)

@pieh pieh self-assigned this Oct 8, 2018
@mslooten
Copy link
Contributor Author

mslooten commented Oct 8, 2018

@pieh Thanks for pointing that out – hadn't considered that. Changed it up a bit so it checks if the path is available.

@ahinrichs
Copy link
Contributor

What about giving some fallback identifier like node.id? This could help to find the error if the markdown isn't a file.

@pieh
Copy link
Contributor

pieh commented Oct 8, 2018

What about giving some fallback identifier like node.id? This could help to find the error if the markdown isn't a file.

It definitely won't hurt. id will often be something like UUID (so not human readable), but I guess it's better feedback that none.

@mslooten
Copy link
Contributor Author

mslooten commented Oct 9, 2018

Cool, can show id as fallback. Can I assume there's always an id available or should that also check for that presence?

@ahinrichs
Copy link
Contributor

BTW, you could also on the fly start using the new createContentDigest API. See #8805.

@pieh
Copy link
Contributor

pieh commented Oct 9, 2018

BTW, you could also on the fly start using the new createContentDigest API. See #8805.

Let's not derail this PR into adding more stuff here :)

Cool, can show id as fallback. Can I assume there's always an id available or should that also check for that presence?

id is required, so it will always be there - it's safe to use that without any checks

As discussed in the PR, it might help people to show the node id when no absolutePath is available (e.g. when not using a file to supply the Markdown)
@mslooten
Copy link
Contributor Author

mslooten commented Oct 9, 2018

@pieh Great, thanks! Added the change to show the node.id.

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mslooten!

@pieh pieh merged commit bbff3be into gatsbyjs:master Oct 9, 2018
@gatsbot
Copy link

gatsbot bot commented Oct 9, 2018

Holy buckets, @mslooten — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@mslooten mslooten deleted the topics/remarkFilename branch July 22, 2020 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more context to error reporting
3 participants