{"record":{"id":"61e3c019e37ea16b","repo":"gohugoio/hugo","slug":"s-is-a-method-of-type-s-but-requires-more-than","errorCode":null,"errorMessage":"%s is a method of type %s but requires more than %d parameter","messagePattern":"(.+?) is a method of type (.+?) but requires more than (.+?) parameter","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/where.go","lineNumber":343,"sourceCode":"\t\tobjPtr = objPtr.Addr()\n\t}\n\n\tmt := hreflect.GetMethodByNameForType(objPtr.Type(), elemName)\n\tif mt.Func.IsValid() {\n\t\t// Receiver is the first argument.\n\t\targs := []reflect.Value{objPtr}\n\t\tnum := mt.Type.NumIn()\n\t\tmaxNumIn := 1\n\t\tif num > 1 && hreflect.IsContextType(mt.Type.In(1)) {\n\t\t\targs = append(args, ctx)\n\t\t\tmaxNumIn = 2\n\t\t}\n\n\t\tswitch {\n\t\tcase mt.PkgPath != \"\":\n\t\t\treturn zero, fmt.Errorf(\"%s is an unexported method of type %s\", elemName, typ)\n\t\tcase mt.Type.NumIn() > maxNumIn:\n\t\t\treturn zero, fmt.Errorf(\"%s is a method of type %s but requires more than %d parameter\", elemName, typ, maxNumIn)\n\t\tcase mt.Type.NumOut() == 0:\n\t\t\treturn zero, fmt.Errorf(\"%s is a method of type %s but returns no output\", elemName, typ)\n\t\tcase mt.Type.NumOut() > 2:\n\t\t\treturn zero, fmt.Errorf(\"%s is a method of type %s but returns more than 2 outputs\", elemName, typ)\n\t\tcase mt.Type.NumOut() == 1 && mt.Type.Out(0).Implements(errorType):\n\t\t\treturn zero, fmt.Errorf(\"%s is a method of type %s but only returns an error type\", elemName, typ)\n\t\tcase mt.Type.NumOut() == 2 && !mt.Type.Out(1).Implements(errorType):\n\t\t\treturn zero, fmt.Errorf(\"%s is a method of type %s returning two values but the second value is not an error type\", elemName, typ)\n\t\t}\n\t\tres := mt.Func.Call(args)\n\t\tif len(res) == 2 && !res[1].IsNil() {\n\t\t\treturn zero, fmt.Errorf(\"error at calling a method %s of type %s: %s\", elemName, typ, res[1].Interface().(error))\n\t\t}\n\t\treturn res[0], nil\n\t}\n\n\t// elemName isn't a method so next start to check whether it is\n\t// a struct field or a map value. In both cases, it mustn't be","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/where.go#L325-L361","documentation":"`evaluateSubElem` (where.go:342-343) will only call a method via reflect if it takes no arguments beyond the receiver, optionally followed by a single `context.Context` as the second parameter (`maxNumIn` is 1, bumped to 2 for context at line 334). If `mt.Type.NumIn()` exceeds `maxNumIn`, the method cannot be invoked by `where` and this error is returned, reporting the allowed count.","triggerScenarios":"`{{ where $users \"FullName\" \"==\" \"Bob\" }}` against `func (u User) FullName(first, last string) string`. Any method whose signature needs caller-supplied arguments other than an optional leading context.","commonSituations":"Author assumes `where` can pass the match value into a finder method; a method was widened to take options and broke a previously-working template; using a builder-style method that takes config.","solutions":["Switch the where key to a zero-arg method or a struct field that already holds the value.","Refactor the element type to expose `func (t) Name(ctx ...context.Context) (T, error)` so it fits the 0-or-context-arg contract.","Pre-compute the value into a field before building the collection."],"exampleFix":"// before\n{{ where $users \"FullName\" \"==\" \"Bob\" }}  {{/* FullName(first, last) */}}\n// after\n{{ where $users \"DisplayName\" \"==\" \"Bob\" }}  {{/* DisplayName() string */}}","handlingStrategy":"validation","validationCode":"// Go-side guard before exposing the collection to templates:\n// ensure the method signature is func() (T[, error]) or func(context.Context) (T[, error])\nmt, ok := reflect.TypeOf(item).MethodByName(name)\nok = ok && mt.Type.NumIn() <= 2 && (mt.Type.NumIn() == 1 || isContext(mt.Type.In(1)))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Design template-callable methods as zero-arg (optionally context) returning one value or (value, error).","Run a unit test that reflect-checks each model method used in templates.","Prefer fields over parameterized methods for `where` keys."],"tags":["hugo","go-templates","where","reflection","method-signature"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}