How is the Hugo Doc site showing shortcodes in code blocks?

I finally figured out the problem, which can be called a subtle bug only in hugo server behavior.

If user adds an invalid shortcode, even in code blocks, hugo server fails and stops just shortcode expansion. So the localhost site serving keeps on going fine.

The issue does not become evident till the user notices the ERROR message on the terminal and runs hugo instead of hugo server.

Post with invalid shortcode

To see the issue, remove the x from {x{ in the test post markdown file, and run hugo server.

Issue

  • The website will generate fine, but with a silent error on the terminal:
    ERROR 2017/11/02 10:37:54 Unable to locate template for shortcode "img" in page "posts/src-block-hugo-shortcoded-undefined.md"
    
  • The hugo server run server will keep on living, and generating the pages almost correctly, while just balking on shortcode expansions!

Source and output (obviously cannot publish with the invalid shortcodes, so will need to make that one modification I mentioned above):

Post with valid shortcode