mtn/cocoa-eh-hugo-theme

Errors on site without expected parameters set

Closed this issue · 7 comments

Hello!

$subj, when trying to run this theme against my blog source I get following (and site won't render):

Building sites … ERROR 2018/03/20 11:47:58 Error while rendering "page" in "post/": template: theme/_default/single.html:1:3: executing "theme/_default/single.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0
ERROR 2018/03/20 11:47:58 Error while rendering "page" in "": template: theme/_default/single.html:1:3: executing "theme/_default/single.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0
ERROR 2018/03/20 11:48:01 Error while rendering "taxonomy" in "": template: theme/_default/taxonomy.html:1:3: executing "theme/_default/taxonomy.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0
ERROR 2018/03/20 11:48:01 Error while rendering "section" in "": template: theme/_default/section.html:1:3: executing "theme/_default/section.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0
ERROR 2018/03/20 11:48:01 Error while rendering "home" in "": template: theme/index.html:1:3: executing "theme/index.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0

Change detected, rebuilding site
2018-03-20 12:10:21.918 +0000
Source changed "/srv/hugo/content/post/2018-03-19-lust-for-text-life.markdown": WRITE
ERROR 2018/03/20 12:10:22 Error while rendering "home" in "": template: theme/index.html:1:3: executing "theme/index.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0
ERROR 2018/03/20 12:10:22 Error while rendering "page" in "post/": template: theme/_default/single.html:1:3: executing "theme/_default/single.html" at <partial "header.html...>: error calling partial: template: theme/partials/header.html:15:88: executing "theme/partials/header.html" at <absURL>: wrong number of args for absURL: want 1 got 0
Total in 1228 ms

The reason is likely some absent .Site. parameters but you can't tell what's exactly wrong from error message, I guess input parameters handling could be improved.

mtn commented

Hm, so this is the same as issue #54, and back then we decided to require the logo. People have also found it to be a recurring challenge, since it was the topic of issue #18 as well.

The problem is that the logofile parameter isn't set, where it must either be set to an image or just be blank to have no logo. If you want no logo, you can just set the parameter to be the empty string, based on #82.

With regards to making ease of use better, I think I'm just going to make a clearer default config.toml with comments, etc. to clearly explain what is required. Also, it would be very easy and probably worthwhile to make a small script for setting them up, or at least one that could ingest a config file and report whether it's valid or if any parameters are missing. I'm pretty sure I could do this all statically just by looking at the theme (and it wouldn't even have to be specific to cocoa-eh) so this is somewhat compelling to me. If you have any thoughts, let me know. 🎈

I'm going to leave the issue open until I make a decision about those 2 potential solutions.

It's all up to you. In my opinion it's strange to require some parameter to be set to empty string in order to be ignored, and it's strange to throw error about absURL when in fact some parameter is not set.
In such situation I would either make error message clearer or handle absence of this parameter properly.
I'm testing two hundred themes now, similar case: https://github.com/wildhaber/gohugo-amp require googleAnalytics to be set in params section of configuration, it renders without errors but instead of rendering actual site content tells you to set this parameter in order to get working site. (In my case it won't work and won't tell me anything after I set it, but that's other story.)

mtn commented

Alright, I think what makes sense as a specific solution to include a link to configuration instructions where the logo should be if no parameter is set, allow no logo if it is set to an empty string, and use the logo otherwise. That way, it's clear what the options are for each case, and the end user doesn't have to encounter hard-to-interpret messages from hugo.

If you have any other thoughts on what better practices are from looking at all those themes, please don't hesitate to open more issues 🎈

mtn commented

Making the change now, and should have it pushed soon. If nothing is set, I'm going to link to configuration instructions on the wiki. Thanks for the suggestion! I'm also going to be making a small linting tool that people will bed able to run their config files against that will generate clean error messages, and a updated example config file that includes all required and optional arguments.

mtn commented

The final product:

screen shot 2018-03-20 at 1 18 33 pm

So when the logofile isn't specified, you get a obnoxious link telling you how to fix things, but the site still builds.

Checked, works fine now, not a single error.

mtn commented

Thanks again!