Empty link causes build error in gatsby develop
macdonst opened this issue ยท 10 comments
gatsby-remark-embedder
version: 1.11.1node
version: 12.14.1npm
(oryarn
) version: 6.13.4
Relevant code or config
[](https://example.com)
What you did:
We had a markdown file that had a weird link formatted like [](https://example.com)
. The text portion of the link was empty.
What happened:
When the graphQL query was run on that file we got an error.
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Cannot query field "htmlAst" on type "MarkdownRemark".
GraphQL request:9:9
8 | childMarkdownRemark {
9 | htmlAst
| ^
10 | tableOfContents
File: src/templates/markdownTemplate.js:92:9
Basically everything under childMarkdownRemark
was null.
Reproduction repository:
Just add a link like [](https://example.com)
to any markdown document in a gatsby project that uses this plugin and you'll be able to reproduce this error.
Problem description:
See above.
Suggested solution:
PR coming in a minute.
@macdonst Can you provide me with an example repo/CodeSandbox please?
I don't understand why you would have a link with an empty child, cause you won't see any link then.
And if you want to just copy the link to a tweet/video/sandbox/..., you can just paste it on that line instead of using the rectangular and round brackets.
@MichaelDeBoey yeah, I agree the link is stupid. I ran into it as a tech writer was using:
[](*****************)
as a visual delimiter.
If the .md file has a link like that in it then all the properties of childMarkdownRemark
are missing. I don't think that anyone should be using a link formatted like that but if they do it will prevent the entire site from being built. Let me create a repo with the reproduction.
@MichaelDeBoey I created a repo with a reproduction at:
https://github.com/macdonst/gatsby-starter-markdown
The file, gatsby-starter-markdown/contents/docs/get-started/introduction.md
contains one of the bad links. When you run gatsby develop
you will see an error like:
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Cannot read property 'value' of undefined
1 | query usersStarterMarkdownsrctemplatespostTemplateJs83022234($path: String!) {
2 | markdownRemark(fields: {slug: {eq: $path}}) {
3 | fields {
4 | slug
5 | }
6 | id
7 | html
8 | tableOfContents
> 9 | timeToRead
| ^
10 | frontmatter {
11 | date(formatString: "MMMM DD, YYYY")
12 | title
13 | root
14 | }
15 | }
16 | }
17 |
File path: /home/gatsby-starter-markdown/src/templates/postTemplate.js
Url path: /docs/get-started/introduction
and if you try and view http://localhost:8001/docs/get-started/introduction you will see the header but not the page contents.
Then if you go into the introduction.md
file and add some text to the empty link the contents of the page should up fine.
@macdonst I've had some thoughts about this and I'm going to close this issue + the accompanied PR, since the use of a link without a child text will never happen in real projects.
If you want to create a visual delimiter you can always use an HTML comment like
<!-- This is a comment -->
@MichaelDeBoey I realize that the likelihood of this happening is very small but the impact when it does happen is very large. Obviously, our tech writer did the wrong thing but the code change is so small and it makes the plugin way more resilient to bad input so I wish you would reconsider.
@MichaelDeBoey I agree with @macdonst, it's a small change and if it makes the plugin more stable. I think we should go for it.
@all-contributors Please add @macdonst for bug
I've put up a pull request to add @macdonst! ๐
๐ This issue has been resolved in version 1.11.2 ๐
The release is available on:
npm package (@latest dist-tag)
- GitHub release
Your semantic-release bot ๐ฆ๐
Thank you @MichaelDeBoey!