Unexpected Error After Latest Blog Post (error calling partial)

Hey all,

I’ve been Hugo for a while now to build my website and have been loving it. I recently wrote a new post and realized that my deployed failed with the following error:

hugo server --watch # -D                                                       
Start building sites …                                                         
WARN 2021/10/01 21:22:37                                                       
                                                                                                                                                              
Current environment is "development". The "comment system", "CDN" and "fingerprint" will be disabled.                                                         当前运行环境是 "development". "评论系统", "CDN" 和 "fingerprint" 不会启用.
                                                                               
WARN 2021/10/01 21:22:37 Page.URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter
 URL value, use .Params.url                                                                                                                                   
Built in 1018 ms                                                               
Error: Error building site: failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:18:90: executing "cont
ent" at <partial "function/content.html">: error calling partial: "/home/ghilston/Git/GregHilston/greghilston/themes/uBlogger/layouts/partials/function/conten
t.html:12:15": execute of template failed: template: partials/function/content.html:12:15: executing "partials/function/content.html" at <partial "function/ch
eckbox.html" $content>: error calling partial: partial that returns a value needs a non-zero argument.

I’m using the uBlogger theme, which has been a very pleasant theme to work with.

What I expect to happen is the site build without any issue, as I seemingly have only written a new blog post and also lately updated uBlogger to the latest commit.

I searched on the forums and found this post, but this does not seem to be related…Additionally, I’ve read that this error can be caused by using .webp images, which I’ve converted to .png files or .jpg files.

Happy to provide any additional information or answer any questions.

error calling partial: partial that returns a value needs a non-zero argument.

looking at partial/function/content.html is returning partial template, the partial consume .Content then return it after transformation.

I throws error because your post has empty content (.Content). You need to make sure that the post has content even whitespace is ok.

example in yaml frontmatter:

---
title: My New Post
---
 

Notice the after the last --- delimiter, it’s newline + space (\n[space]).

Second Method, by editing the partial template itself

Edit partials/function/content.html,

Create fallback value if .Content is empty:

-- {{- $content := .Content  -}}
++ {{- $content := or .Content " " -}}

Hmm interesting. Every post that I’ve written has non empty content. IE there’s text after the yaml frontmatter. I’m looking for a bash command to run to double check this programatically, as I just went through manually and checked every post I’ve written in the past few weeks…

When applying your second method, I uncovered something interesting. I got a different error which bubbled up from my latest post:

Error: Error building site: "/home/ghilston/Git/GregHilston/greghilston/themes/uBlogger/layouts/_default/_markup/render-link.html:2:16": execute of template failed: template: _default/_markup/render-link.html:2:64: executing "_default/_markup/render-link.html" at <partial "function/resource.html">: error calling partial: "/home/ghilston/Git/GregHilston/greghilston/themes/uBlogger/layouts/partials/function/resource.html:2:16": execute of template failed: template: partials/function/resource.html:2:16: executing "partials/function/resource.html" at <urls.Parse>: error calling Parse: parse "192.168.1.5:8000": first path segment in URL cannot contain colon

I had this line in my post:

192.168.1.5:8000

I’m writing a post about self hosting a server and wanted to provide a simple link to said locally hosted server.

By removing that line from my post, I was able to successfully build my site.

Any ideas why this error was hidden from the first one? I’m a bit confused why we were unable to see the real error until we applied the method two?

I doubt I uncovered a bug in Hugo, but rather perhaps broke some markdown rule that I was unaware of and didn’t get the friendliest of error messages…

When was the last time you updated the theme?

I ask because an empty .Content check was added to:
layouts/partials/function/content.html

in 99551a9 on December 2, 2020.

Chasing errors in an older version of a theme is probably not a wise investment of your time.

@jmooring interesting find! I’m actually up to date with the uBlogger Git repository. IE: my latest commit is: e9896a0d17830f263e4d44e55b21feb7416fe85d.

Any other thoughts to why having the line [192.168.1.2:5000](192.168.1.2:5000] would be a problem?

I worked around this problem by not making the above a URL, and instead just had the string hard coded, but I’m very curious:

  1. Why this line was an issue
  2. Why the error wasn’t visible until I added the change to layouts/partials/function/content.html

There are no errors when content is:

[192.168.1.2:5000](192.168.1.2:5000]

Do you mean?

[192.168.1.2:5000](192.168.1.2:5000)

Yes you’re correct, I mistyped. I’m on my phone so forgive me.

Withtthat correction do you, or anyone else, have any idea why that specific part of a single blob post gives a cryptic error?

Short Answer

Leave the theme at e9896a0 (no modificiations required) and change your markdown to:

[192.168.1.2:5000](https://192.168.1.2:5000)

Long Answer

1) The uBlogger theme defines a link render hook at layouts/_default/_markup/render-link.html. Any markdown detected as a link is passed through this hook.

2) The link render hook calls layouts/partials/function/resource.html, which calls the Hugo urls.Parse function.

3) The Hugo urls.Parse function is based on the Parse function from the golang url package:

Parse parses a raw url into a URL structure.

The url may be relative (a path, without a host) or absolute (starting with a scheme). Trying to parse a hostname and path without a scheme is invalid but may not necessarily return an error, due to parsing ambiguities.

4) If you pass an IP address to the golang Parse function, it treats it as a path.

raw url Scheme Hostname Port Path
https://192.168.1.2 https 192.168.1.2
https://192.168.1.2:5000 https 192.168.1.2 5000
https://192.168.1.2:5000/foo https 192.168.1.2 5000 /foo
192.168.1.2 192.168.1.2

5) If you pass an IP address with port number (example: 192.168.1.2:5000) to the golang Parse function, it treats it as a path and throws this error:

first path segment in URL cannot contain colon

6) I think the error thrown by urls.Parse causes .Content to become nil, which results in this error:

Error: Error building site: failed to render pages: render of “page” failed: execute of template failed: template: posts/single.html:277:98: executing “no-content” at <partial “function/content.html”>: error calling partial: “/home/jmooring/code/hugo-testing/themes/uBlogger/layouts/partials/function/content.html:12:15”: execute of template failed: template: partials/function/content.html:12:15: executing “partials/function/content.html” at <partial “function/checkbox.html” $content>: error calling partial: partial that returns a value needs a non-zero argument.

7) Unfortunately, for whatever reason, the error above masks the error thrown by urls.Parse.

Next Steps

The theme author checks for empty content:
https://github.com/uPagge/uBlogger/blob/master/layouts/partials/function/content.html#L3

{{- if ne "" $content -}}

They should also check for nil content:

{{- if and (ne "" $content) (ne nil $content) -}}

Or wrap with with:

{{- $content := .Content -}}
{{- $ruby := .Ruby -}}
{{- $fraction := .Fraction -}}

{{- with $content -}}
  {{- if $ruby -}}
      {{- $content = partial "function/ruby.html" $content -}}
  {{- end -}}
  {{- if $fraction -}}
      {{- $content = partial "function/fraction.html" $content -}}
  {{- end -}}
  {{- $content = partial "function/checkbox.html" $content -}}
  {{- $content = partial "function/escape.html" $content -}}
{{- end -}}

{{- return $content -}}
1 Like

Holy cow @jmooring, what a high quality reply.

This makes perfect sense. Thank you 100% for explaining this, as the I found the situation Esther confusing.

I’ve marked your message as the solution and want to let you know how much appreciate you and thank you for your time :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.