{"record":{"id":"e708c1090759de59","repo":"gohugoio/hugo","slug":"call-of-nil","errorCode":null,"errorMessage":"call of nil","messagePattern":"call of nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/texttemplate/funcs.go","lineNumber":315,"sourceCode":"\tswitch item.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String:\n\t\treturn item.Len(), nil\n\t}\n\treturn 0, fmt.Errorf(\"len of type %s\", item.Type())\n}\n\n// Function invocation\n\nfunc emptyCall(fn reflect.Value, args ...reflect.Value) reflect.Value {\n\tpanic(\"unreachable\") // implemented as a special case in evalCall\n}\n\n// call returns the result of evaluating the first argument as a function.\n// The function must return 1 result, or 2 results, the second of which is an error.\nfunc call(name string, fn reflect.Value, args ...reflect.Value) (reflect.Value, error) {\n\tfn = indirectInterface(fn)\n\tif !fn.IsValid() {\n\t\treturn reflect.Value{}, fmt.Errorf(\"call of nil\")\n\t}\n\ttyp := fn.Type()\n\tif typ.Kind() != reflect.Func {\n\t\treturn reflect.Value{}, fmt.Errorf(\"non-function %s of type %s\", name, typ)\n\t}\n\n\tif err := goodFunc(name, typ); err != nil {\n\t\treturn reflect.Value{}, err\n\t}\n\tnumIn := typ.NumIn()\n\tvar dddType reflect.Type\n\tif typ.IsVariadic() {\n\t\tif len(args) < numIn-1 {\n\t\t\treturn reflect.Value{}, fmt.Errorf(\"wrong number of args for %s: got %d want at least %d\", name, len(args), numIn-1)\n\t\t}\n\t\tdddType = typ.In(numIn - 1).Elem()\n\t} else {\n\t\tif len(args) != numIn {","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/texttemplate/funcs.go#L297-L333","documentation":"Raised by the `call` template action (`{{call .Fn args}}`) when the function value is invalid (funcs.go:313-315) — i.e. untyped nil. `call` requires an actual function value; a nil interface cannot be invoked.","triggerScenarios":"`{{call .Handler}}` where `.Handler` is nil or absent from the context; passing a missing map key as a function; calling a variable that a conditional branch left unset.","commonSituations":"Optional callbacks; function maps where the name was misspelled; conditional logic that only assigns the callable in some branches.","solutions":["Guard: `{{with .Fn}}{{call .}}{{end}}`.","Provide a default no-op function in Go.","Verify the name/value is set in the FuncMap or context."],"exampleFix":"// before\n{{call .Render}}   // .Render is nil\n\n// after\n{{with .Render}}{{call .}}{{end}}","handlingStrategy":"validation","validationCode":"// Guard the callable:\n//   {{with .Fn}}{{call .}}{{end}}\n// Provide a no-op default in Go if the value may be absent.","typeGuard":"func isCallable(v interface{}) bool {\n    return v != nil && reflect.TypeOf(v).Kind() == reflect.Func\n}","tryCatchPattern":null,"preventionTips":["Always guard `call` with {{with}} for optional callables.","Provide a default no-op function in FuncMap.","Spell-check function names in templates against the FuncMap."],"tags":["template","call","nil","text-template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}