Len of untyped nil

$ hugo version
Hugo Static Site Generator v0.25.1 darwin/amd64 BuildDate: 2017-07-17T13:59:37-07:00
$ hugo server --buildDrafts
Started building sites …
ERROR 2017/07/17 14:15:20 Error while rendering “home”: template: theme/index.html:20:11: executing “theme/index.html” at <partial "features.ht…>: error calling partial: template: theme/partials/features.html:3:10: executing “theme/partials/features.html” at <len .Site.Data.featu…>: error calling len: len of untyped nil
Built site for language en:

So - the site renders, but all I get is an icon with no other content.

I recently updated to the latest clone of hugo-universal-themes, which generated a bunch of errors, so I also updated to the latest version of Hugo. Ideally I’d be set, but I have no idea how out of date my config.toml may be, or how to update it appropriately.

1 Like

What is your question?

To get the best support from here you’ll need to solve your errors one at a time, and ask about the roadblocks you hit. Also, put your code up in a public repo, so folks can see it when you have questions.

I have the same issue today. i copied the config.toml to the root, and when i try to view via localhost:1313, i get the same error. Of course am new to this but tracked the code error to the features.html, thing is I am looking at 20:11 in index.html
with tis

{{ partial “head.html” . }}

<div id="all">

    <header>

      {{ partial "top.html" . }}

      {{ partial "nav.html" . }}

    </header>

    {{ partial "carousel.html" . }}

–> {{ partial “features.html” . }} <— this line

    {{ partial "testimonials.html" . }}

    {{ partial "see_more.html" . }}

    {{ partial "recent_posts.html" . }}

    {{ partial "clients.html" . }}

    {{ partial "footer.html" . }}

</div>
<!-- /#all -->

{{ partial "scripts.html" . }}

and then I am referencing the features.html:

{{ if isset .Site.Params “features” }}
{{ if .Site.Params.features.enable }}
—> {{ if gt (len .Site.Data.features) 0 }} <-- this line is referenced

{{ range $index, $element := sort .Site.Data.features "weight" }} {{ if eq (mod $index 3) 0 }}
{{ end }}

{{ $element.name }}

{{ $element.description | markdownify }}

{{ if or (eq (mod $index 3) 2) (eq $index (sub (len $.Site.Data.features) 1 )) }}
{{ end }} {{ end }}
{{ end }} {{ end }} {{ end }}

I cannot figure out what the issue is. Any help will be very appreciated. Thanks!

Hello @MorseGates,

nil denotes the absence of a value. In this context I would guess that there is not file called features.{toml, yaml or json} in the data/ folder. The referenced line that you highlighted bold tries to access the data in this (non-existing) file, hence nil is returned.

But len expects some kind of sequence whose length can be determined. An absent sequence will cause an error. Make sure you copy all necessary files from the exampleSite folder into the corresponding folders in the root directory of your hugo site.

2 Likes

Hello digitalcraftsman,
Indeed, that was the issue. I copied the necessary files and Its up now! I thank you!
I will link this as fixed in the git site as I opened a request there as well.

Great to hear that your issue is fixed. Happy Hugoing :slight_smile:

1 Like