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(plugin-content-docs): fix error message context (error cause) when doc processing fails #8234

Merged
merged 7 commits into from Oct 26, 2022

Conversation

shanpriyan
Copy link
Contributor

@shanpriyan shanpriyan commented Oct 21, 2022

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

await the promise from doProcessDocMetadata and throw error if it fails

Test links

Deploy preview: https://deploy-preview-8234--docusaurus-2.netlify.app/

Related issues/PRs

Resolves #8230
Suggested fix #8230 (comment)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 21, 2022
@netlify
Copy link

netlify bot commented Oct 21, 2022

[V2]

Name Link
🔨 Latest commit 8c2eb58
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/635927fe2fad4500084d5056
😎 Deploy Preview https://deploy-preview-8234--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Oct 21, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 76 🟢 97 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 82 🟢 100 🟢 100 🟢 100 🟢 90 Report

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

good start thanks 👍

Can you also please add a unit test somewhere so that we be sure it works and never stops working again?

packages/docusaurus-plugin-content-docs/src/docs.ts Outdated Show resolved Hide resolved
packages/docusaurus-plugin-content-docs/src/docs.ts Outdated Show resolved Hide resolved
@shanpriyan
Copy link
Contributor Author

shanpriyan commented Oct 21, 2022

Can you also please add a unit test somewhere so that we be sure it works and never stops working again?

Actually I'm not very familiar with writing tests 😅, If you could guide me I'll add it. Any links to similar tests would be appreciated

@slorber
Copy link
Collaborator

slorber commented Oct 21, 2022

You can get inspiration from: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts#L684

Create a md file with the bad frontmatter that should get rejected, then run the fn in a test and assert that the correct error message was thrown.

Run yarn test docs.test.ts --watch to run this specific test file. Jest provides it.only( and describe.only( to focus on a specific test case.

Actually I think some existing tests might cover the error message already, and will start failing with your fix because the message is now updated to something better: you may have to change the assertions/snapshots to reflect the change.

I'm not sure how Jest plays well with Error Cause, may have to look into it myself later. Let me know if you don't find a solution. If you want to contribute to open-source it will be important to be able to write tests so it's worth you give it a try ;)

@shanpriyan
Copy link
Contributor Author

shanpriyan commented Oct 21, 2022

You can get inspiration from: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts#L684

Create a md file with the bad frontmatter that should get rejected, then run the fn in a test and assert that the correct error message was thrown.

Run yarn test docs.test.ts --watch to run this specific test file. Jest provides it.only( and describe.only( to focus on a specific test case.

This would be helpful to get started, thanks

If you want to contribute to open-source it will be important to be able to write tests so it's worth you give it a try ;)

😄Will definitely consider your advice and I'll give this a try 🚀

@shanpriyan
Copy link
Contributor Author

shanpriyan commented Oct 22, 2022

Actually I think some existing tests might cover the error message already, and will start failing with your fix because the message is now updated to something better: you may have to change the assertions/snapshots to reflect the change.

fixed existing test case (updated snapshot with latest error message) which failed due to change in error message

Before Fix After fix
image image

@shanpriyan
Copy link
Contributor Author

@slorber since the below test case covers the latest error message (a532ed0), Do I need to add a new test case?

it('docs with invalid id', async () => {

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Oct 26, 2022
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks 👍

Fixed the test to assert that we have the full error cause chain being tested

@slorber slorber changed the title fix: await docMetaData and handle error fix(plugin-content-docs): fix error message context (error cause) when doc processing fails Oct 26, 2022
@slorber slorber merged commit 91b92fc into facebook:main Oct 26, 2022
@shanpriyan shanpriyan deleted the fix/handle-metadata-error branch October 26, 2022 13:02
@slorber slorber added the to backport This PR is planned to be backported to a stable version of Docusaurus label Oct 26, 2022
slorber added a commit that referenced this pull request Oct 28, 2022
…n doc processing fails (#8234)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
@slorber slorber added backported This PR has been backported to a stable version of Docusaurus and removed to backport This PR is planned to be backported to a stable version of Docusaurus labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR has been backported to a stable version of Docusaurus CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

front matter validation does not print a good error message
3 participants