{"record":{"id":"1a477cfc7ae72e6a","repo":"gohugoio/hugo","slug":"non-function-s-of-type-s","errorCode":null,"errorMessage":"non-function %s of type %s","messagePattern":"non-function (.+?) of type (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/texttemplate/funcs.go","lineNumber":319,"sourceCode":"\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 {\n\t\t\treturn reflect.Value{}, fmt.Errorf(\"wrong number of args for %s: got %d want %d\", name, len(args), numIn)\n\t\t}\n\t}\n\targv := make([]reflect.Value, len(args))","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/texttemplate/funcs.go#L301-L337","documentation":"Raised by the `call` action when the value is valid but its Kind is not Func (funcs.go:317-319). `call` only invokes functions/methods; invoking a struct, slice, map, int, etc. is rejected. Format: `name type`.","triggerScenarios":"`{{call .S 5}}` where `.S` is a slice; `{{call .Name}}` on a string; `{{call . 1}}` on a non-function root; shadowing a function name with a data field of a different type.","commonSituations":"Name collision between a FuncMap entry and a data field; passing a method value incorrectly; refactoring a callback field to a non-callable type.","solutions":["Print the type: `{{printf \"%T\" .X}}`.","Ensure the value is a func registered in FuncMap or a method on the struct.","Use direct method invocation `{{.Method args}}` instead of `call` where possible."],"exampleFix":"// before\n{{call .Items 0}}   // .Items is []string\n\n// after\n{{index .Items 0}}","handlingStrategy":"type-guard","validationCode":"// Verify it's a function before calling:\n//   {{printf \"%T\" .X}}\n// Only Kind == Func can be invoked via call.","typeGuard":"func isFunc(v interface{}) bool {\n    return v != nil && reflect.TypeOf(v).Kind() == reflect.Func\n}","tryCatchPattern":null,"preventionTips":["Avoid name collisions between FuncMap entries and data fields.","Prefer direct method invocation {{.M args}} over {{call}}.","Inspect the type with {{printf \"%T\"}} when call fails."],"tags":["template","call","reflection","text-template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}