Why partials raise "can't evaluate field <key> in type" when it renders the output correctly?

I have an index.html containing 2 partials reading from the same data file (.Site.Data.myTheme.owner.toml) file. Hugo is able to render both partials correctly but the second partials raise something as such in -verbose mode:

ERROR 2017/04/02 11:34:44 theme/partials/footer.html template: theme/partials/footer.html:6:9: executing "theme/partials/footer.html" at <.socials>: can't evaluate field socials in type *hugolib.Page

Is this error a false alarm or did I miss something out?

NOTE:

If I use .Site.Data.myTheme.owner.socials directly inside the partial, it will remove the error. However, this is not feasible since I wanted the partials to read the data file instead of hardcoding.


My simplified `index.html` code is as follows, which is working: ``` {{ partial "contact.html" .Site.Data.myTheme.owner }} {{ partial "footer.html" .Site.Data.myTheme.owner }} ```
The `footer.html` partials is as follows: ```


{{ .email }}

{{ .address }}


© 2017 {{ .name }}. All Rights Reserved.


```
and the generated output is as follows: ```
						<li><a href="#">
							<i class="fa fa-facebook x1"></i>Facebook
						</a></li>

						<li><a href="#">
							<i class="fa fa-twitter x1"></i>Twitter
						</a></li>

						<li><a href="#">
							<i class="fa fa-instagram x1"></i>Instagram
						</a></li>

						<li><a href="#">
							<i class="fa fa-behance x1"></i>Behance
						</a></li>

				</ul>
				<div class="footer-info">
						<h6><i class="fa fa-envelope-o pr5"></i>support@myTheme.com</h6>
						<h6><i class="fa fa-home pr5"></i>Address Field Here</h6>
				</div>
				<h6>© 2017 myTheme. All Rights Reserved.</h6>
		</div>
</div>
```

Found the issue during a recursive code reviews. Apparently, I didn’t update 404.html page that uses the same partials. Hence, the error occurred.

The error message does not describe parent file that the issue has caused, hence, left me hanging in the air wondering the source for the colorful mystery. Also, it doesn’t terminate the build process so at first thought, the error is assumed a workaround bug.

Hey,

I just added a test to verify that Hugo now (as in Hugo 0-20-DEV) includes the container template in the error message in this case.

And Hugo does, which makes debugging these situations much easier.

I also added a fix so we don’t log an entry for every such failure, spamming the log. Here is an example output from my blog:

Started building sites ...
ERROR 2017/04/02 12:19:43 Error while rendering "page": template: /Users/bep/sites/bepsays.com/layouts/_default/single.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/_default/single.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "section": template: /Users/bep/sites/bepsays.com/layouts/_default/section.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/_default/section.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "taxonomy": template: /Users/bep/sites/bepsays.com/layouts/_default/list.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/_default/list.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "home": template: /Users/bep/sites/bepsays.com/layouts/index.html:17:7: executing "/Users/bep/sites/bepsays.com/layouts/index.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
ERROR 2017/04/02 12:19:43 Error while rendering "404": template: 404.html:2:3: executing "404.html" at <partial "menu.html" ...>: error calling partial: template: partials/menu.html:9:11: executing "partials/menu.html" at <.DoesNotExist>: can't evaluate field DoesNotExist in type *hugolib.PageOutput
Built site for language nn:
1 Like

Thanks bep!

Your error message is very meaningful than the existing version. Definitely love it and looking forward to it.