Hugo: Show the Error messages in the HTML in some form to alert the user when running hugo server

Created on 2 Nov 2017  路  6Comments  路  Source: gohugoio/hugo

Recently I came across seeing strange results in hugo server generated pages, that were different from expectation.. hugo should have parsed the shortcode snippets with comment chars in a special way, but that didn't happen.

Turns out that hugo server was throwing an error.. but it still generated the full pages except for parsing shortcodes. This led to quite some confusion.. details in the link at the end of this issue.

Suggestion

Can hugo introduce a warning message at the top of the generated HTML body.. some sort of banner that says "Hey, check the ERROR on terminal", or even even better!! Put out that Error in that banner when running hugo server?


Enhancement

Most helpful comment

Why wouldn't聽hugo server聽exit -1聽in the same way as regular聽hugo? Wouldn't that be simplest?

This is a not uncommon edit session for me:

  1. Start server with hugo server
  2. Edit ... then do some bad edit, e.g. forget to close a shortcode. I notice the ERROR in the console.
  3. I try to fix the ERROR... Hmm ... The error is still there.
  4. OK, now I got it! I have to close the shortcode! The ERROR goes away!

Imagine that same sequence if we exit -1 on errors in hugo server:

  1. Start server with hugo server
  2. Edit ... then do some bad edit, e.g. forget to close a shortcode. I notice the ERROR in the console.
  3. I try to fix the ERROR
  4. Restart the server. Hmm ... The error is still there.
  5. OK, now I got it! I have to close the shortcode!
  6. Restart the server. The ERROR goes away!

I think the current behaviour is more user friendly.

All 6 comments

Ideally there is some data structure on Page where all error messages and any other dev-time info (e.g. debug info per #3514) can be collected, and then the renderer puts all of it in a banner or whatever makes sense for the output format.

Ideally there is some data structure on Page where all error messages and any other dev-time info (e.g. debug info per #3514) can be collected

I don't think it would make sense to pin this to a Page -- that would be hard and not worth it. The viable option is to ask: It this was regular hugo and we would exit -1, then show "that error" to the user.

That makes sense. My suggestion was if the solution was along the lines of the title of this issue, "Show the Error messages in the HTML".

Or are you saying show "that error" on every page... i.e. hugo server (not the renderers) would simply insert it as a banner at the top?

Or are you saying show "that error" on every page... i.e. hugo server would simply insert it as a banner at the top (not something the renderers would do)?

I would try to make it as simple as possible. Render it on 1 or every page makes no practical difference for the user (he/she is only looking at one). We have a list of "recently viewed" pages stored away (used for the "rast render mode") and could use that to only render the error message on "the current", but I would only do that if it was really simple.

The error message should anyhow be as detailed as in the console so the user would know what page it is about (if not the current).

An alternative approach that may be worth visiting is to use JavaScript (see the LiveReload integration) to trigger some kind of alert.

Why wouldn't hugo server exit -1 in the same way as regular hugo? Wouldn't that be simplest?

Is it because it makes sense to render and display whatever did work to make debugging easier?

Why wouldn't聽hugo server聽exit -1聽in the same way as regular聽hugo? Wouldn't that be simplest?

This is a not uncommon edit session for me:

  1. Start server with hugo server
  2. Edit ... then do some bad edit, e.g. forget to close a shortcode. I notice the ERROR in the console.
  3. I try to fix the ERROR... Hmm ... The error is still there.
  4. OK, now I got it! I have to close the shortcode! The ERROR goes away!

Imagine that same sequence if we exit -1 on errors in hugo server:

  1. Start server with hugo server
  2. Edit ... then do some bad edit, e.g. forget to close a shortcode. I notice the ERROR in the console.
  3. I try to fix the ERROR
  4. Restart the server. Hmm ... The error is still there.
  5. OK, now I got it! I have to close the shortcode!
  6. Restart the server. The ERROR goes away!

I think the current behaviour is more user friendly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrissparksnj picture chrissparksnj  路  3Comments

vielmetti picture vielmetti  路  3Comments

kaushalmodi picture kaushalmodi  路  3Comments

sigma picture sigma  路  3Comments

digitalcraftsman picture digitalcraftsman  路  3Comments