[Solved using HEAD] Need help figuring out why Hugo crashes (panic: reflect: call of reflect.Value.Len on zero Value)

I have two sites I am building using the same theme and hugo install. Running Hugo on site 1 gives me no issues. Running Hugo on site 2 crashes Hugo with the following console output. Since they are running the same theme (symlinked even), I am assuming that something in my ./content is to blame (haven’t changed my config in a very long while)

$ hugo
Started building site
panic: reflect: call of reflect.Value.Len on zero Value [recovered]
	panic: reflect: call of reflect.Value.Len on zero Value

goroutine 123 [running]:
panic(0x75e0e0, 0xc820394ce0)
	/usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:481 +0x3e6
text/template.errRecover(0xc82055f0d8)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:139 +0x2f0
panic(0x75e0e0, 0xc820394ce0)
	/usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:443 +0x4e9
reflect.Value.Len(0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.6.2/libexec/src/reflect/value.go:1015 +0xd2
github.com/spf13/hugo/hugolib.(*ShortcodeWithPage).Get(0xc820516b00, 0x66d880, 0xc8204aed60, 0x0, 0x0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/shortcode.go:69 +0xae
reflect.Value.call(0x7e3de0, 0xc820516b00, 0x213, 0x86a810, 0x4, 0xc820394c40, 0x1, 0x1, 0x0, 0x0, ...)
	/usr/local/Cellar/go/1.6.2/libexec/src/reflect/value.go:435 +0x120d
reflect.Value.Call(0x7e3de0, 0xc820516b00, 0x213, 0xc820394c40, 0x1, 0x1, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.6.2/libexec/src/reflect/value.go:303 +0xb1
text/template.(*state).evalCall(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0x7e3de0, 0xc820516b00, 0x213, 0xf18938, 0xc8204705d0, 0xc82046e30b, ...)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:641 +0xb39
text/template.(*state).evalField(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0xc82046e30b, 0x3, 0xf18938, 0xc8204705d0, 0xc82046c340, 0x2, ...)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:534 +0x350
text/template.(*state).evalFieldChain(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0x7e3de0, 0xc820516b00, 0x16, 0xf18938, 0xc8204705d0, 0xc8204419e0, ...)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:505 +0x29d
text/template.(*state).evalFieldNode(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0xc8204705d0, 0xc82046c340, 0x2, 0x2, 0x0, 0x0, ...)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:469 +0x1e2
text/template.(*state).evalCommand(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0xc8204705a0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:407 +0xa91
text/template.(*state).evalPipeline(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0xc820468960, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:385 +0x180
text/template.(*state).walkIfOrWith(0xc82055f068, 0xa, 0x7e3de0, 0xc820516b00, 0x16, 0xc820468960, 0xc820470600, 0x0)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:244 +0xb5
text/template.(*state).walk(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0xf1feb8, 0xc820472000)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:220 +0x4d9
text/template.(*state).walk(0xc82055f068, 0x7e3de0, 0xc820516b00, 0x16, 0xf959c0, 0xc820470540)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:223 +0x6a1
text/template.(*Template).Execute(0xc820451f00, 0xf1b490, 0xc82013e1c0, 0x7e3de0, 0xc820516b00, 0x0, 0x0)
	/usr/local/Cellar/go/1.6.2/libexec/src/text/template/exec.go:178 +0x2a7
html/template.(*Template).Execute(0xc8204704e0, 0xf1b490, 0xc82013e1c0, 0x7e3de0, 0xc820516b00, 0x0, 0x0)
	/usr/local/Cellar/go/1.6.2/libexec/src/html/template/template.go:104 +0x9a
github.com/spf13/hugo/hugolib.renderShortcodeWithPage(0xc8204704e0, 0xc820516b00, 0x0, 0x0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/shortcode.go:562 +0x122
github.com/spf13/hugo/hugolib.renderShortcode(0xc8201009c2, 0x3, 0xc8204b0c00, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, ...)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/shortcode.go:271 +0xaac
github.com/spf13/hugo/hugolib.renderShortcode(0xc8201008e7, 0x3, 0xc8203cac00, 0xb, 0x10, 0x655d40, 0xc8203c2f60, 0x0, 0x0, 0x1, ...)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/shortcode.go:227 +0x5d0
github.com/spf13/hugo/hugolib.renderShortcodes(0xc8202a8c30, 0xc82029a400, 0xf51800, 0xc8201e4690, 0xc8201e4690)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/shortcode.go:305 +0x214
github.com/spf13/hugo/hugolib.extractAndRenderShortcodes(0xc820100000, 0x18ce, 0xc82029a400, 0xf51800, 0xc8201e4690, 0x0, 0x0, 0x11, 0x0, 0x0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/shortcode.go:291 +0x290
github.com/spf13/hugo/hugolib.(*Page).ProcessShortcodes(0xc82029a400, 0xf51800, 0xc8201e4690)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/page.go:912 +0xa2
github.com/spf13/hugo/hugolib.commonConvert(0xc82029a400, 0xf51800, 0xc8201e4690, 0x0, 0x0, 0x0, 0x0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/handler_page.go:113 +0x6f
github.com/spf13/hugo/hugolib.markdownHandler.PageConvert(0x0, 0x0, 0x0, 0xc82029a400, 0xf51800, 0xc8201e4690, 0x0, 0x0, 0x0, 0x0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/handler_page.go:60 +0x51
github.com/spf13/hugo/hugolib.(*markdownHandler).PageConvert(0xc82019ffa0, 0xc82029a400, 0xf51800, 0xc8201e4690, 0x0, 0x0, 0x0, 0x0)
	<autogenerated>:111 +0xde
github.com/spf13/hugo/hugolib.(*MetaHandle).Convert(0xc820196da0, 0x8605e0, 0xc82029a400, 0xc820348000, 0xc8203c8cc0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/handler_meta.go:77 +0x43d
github.com/spf13/hugo/hugolib.pageConverter(0xc820348000, 0xc8203c8d20, 0xc8203c8cc0, 0xc8204b2ce0)
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/site.go:967 +0x108
created by github.com/spf13/hugo/hugolib.(*Site).convertSource
	/private/tmp/hugo-20160607-37510-1daro23/hugo-0.16/src/github.com/spf13/hugo/hugolib/site.go:900 +0x192

Update: This issue went away after I switched to using the HEAD version (at the time of writing v0.17-DEV). For anybody wanting to install the HEAD version via homebrew:

  1. Remove existing version brew uninstall hugo. You might need to do a brew uninstall --force hugo if you have multiple versions installed (e.g. Hugo v0.16 installed over a previous version, e.g. v0.15)
  2. Compile hugo from source: brew install --build-from-source --HEAD hugo

That’s it!

Ok, I found the trigger, but I do not understand why. I first had following shortcode in div.html:

<div>{{ .Inner }}</div>

which I then changed to:

<div{{ if .Get "class" }} class='{{ .Get "class" }}'{{ end }}{{ if .Get "id" }} id='{{ .Get "id" }}'{{ end }}>{{ .Inner }}</div>

This change crashes site 1 but not site 2. In the site 1 that crashes, I never use a parameter with the shortcode. I tried adding an instance of `{{% div class=“box” %}} to site 1 to test this, but it still crashes. My content in site 2 has shortcode calls both with and without parameters.

Update: Adding the modified div shortcode as divclass.html does not crash the site either, so I’m sticking with that solution for now.