gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.76k stars 7.46k forks source link

Invalid/incomplete shortcode breaks *all* shortcodes #5790

Closed stephenfin closed 5 years ago

stephenfin commented 5 years ago

I'm switching my docs from rST to Markdown and trying to take advantage of shortcodes in the process. However, I am noticing some usability issues in the process. I created something like this:

---
title: "Welcome"
date: 2019-03-25T13:43:58Z
---

Hello, world. Here is some text.

{{< gist spf13 7896402 >}}

{{% note %}}
Here is a piece of information I would like to draw your **attention**** to.
{{% /note %}}

When I ran hugo serve, none of the shortcodes were rendered. I noticed the following logs:

Change detected, rebuilding site
2019-03-25 13:48:57.447 +0000
Source changed "/tmp/test-hugo/content/post/welcome.md": WRITE
ERROR 2019/03/25 13:48:57 Unable to locate template for shortcode "note" in page "post/welcome.md"
Total in 13 ms

However, I didn't pay much attention to this because the thing still ran and sort of rendered. Eventually I figured out that if I dropped the {{% note %}}{{% /note %}} shortcode, the {{<gist>}} one suddenly started working. Once I'd figured that out, I realized that the definition of the former in the docs was only given as an example and is not included out of the box.

This has caught me out before and I doubt I'm the only one. Ideally, I think the build/serve operations should fail to run in the above case. Alternatively, I think the broken shortcodes should be replaced with some kind of warning that states that there is an issue (this is what docutils does). In any case, it really shouldn't just fail sort of silently like it's doing here.

I can try fix this myself but I'd like to know if the idea is sound before I invest the time in an unwanted fix.

bep commented 5 years ago

This has caught me out before and I doubt I'm the only one. Ideally, I think the build/serve operations should fail to run in the above case

First, I suspect you are running an old version of Hugo. But are you sure it does not fail to run? And by failing I mean: 1) Log an ERROR and 2) Exit with an exit code != 0 (also note that we do not stop the server on errors, that would be just painful ...)

stephenfin commented 5 years ago

Thanks for the quick reply. Indeed, my version does look quite old:

$ hugo version
Hugo Static Site Generator v0.37.1 linux/amd64 BuildDate

(I see the latest appears to be 0.54.0).

This is the version packaged on Fedora. I can probably encourage someone to update this.

You are also correct in suggesting that the exit code is non-zero (255, to be exact) and that stopping the server on error would be painful. The exit code wasn't much more obvious than the error log though.

What are your thoughts on including the errors in the built document when using the server? We probably don't want to include it in the built docs but that could be configurable, I guess.

Jos512 commented 5 years ago

What are your thoughts on including the errors in the built document when using the server? We probably don't want to include it in the built docs.

This feature is added in Hugo 0.50. It's called 'browser error' in Hugo and they don't show when you build the site (only appear with hugo server).

This is the version packaged on Fedora. I can probably encourage someone to update this.

This Fedora Copr version is updated till 0.54. Here's a list of other places where you can fetch the latest Hugo package.

stephenfin commented 5 years ago

Excellent, thanks. Seems like this is resolved and I just need to use that Copr or encourage someone to update the main repo. I guess this can be closed now

stephenfin commented 5 years ago

For anyone that stumbles upon this, it seems Fedora 30 will include Hugo 0.54. One less thing for me to do \o/

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.