{"record":{"id":"d7d5cbfad31a75fd","repo":"gohugoio/hugo","slug":"arg-d-w","errorCode":null,"errorMessage":"arg %d: %w","messagePattern":"arg (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/internal/go_templates/texttemplate/funcs.go","lineNumber":348,"sourceCode":"\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))\n\tfor i, arg := range args {\n\t\targ = indirectInterface(arg)\n\t\t// Compute the expected type. Clumsy because of variadics.\n\t\targType := dddType\n\t\tif !typ.IsVariadic() || i < numIn-1 {\n\t\t\targType = typ.In(i)\n\t\t}\n\n\t\tvar err error\n\t\tif argv[i], err = prepareArg(arg, argType); err != nil {\n\t\t\treturn reflect.Value{}, fmt.Errorf(\"arg %d: %w\", i, err)\n\t\t}\n\t}\n\treturn safeCall(fn, argv)\n}\n\n// safeCall runs fun.Call(args), and returns the resulting value and error, if\n// any. If the call panics, the panic value is returned as an error.\nfunc safeCall(fun reflect.Value, args []reflect.Value) (val reflect.Value, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tif e, ok := r.(error); ok {\n\t\t\t\terr = e\n\t\t\t} else {\n\t\t\t\terr = fmt.Errorf(\"%v\", r)\n\t\t\t}\n\t\t}\n\t}()\n\tret := fun.Call(args)","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/internal/go_templates/texttemplate/funcs.go#L330-L366","documentation":"Raised by the `call` action when `prepareArg` fails to coerce argument `i` to the function's declared parameter type (funcs.go:347-348). The underlying error (nil-mismatch or wrong type) is wrapped with the arg position. Causes: passing nil to a non-nillable param, or a value whose type is not assignable/convertible.","triggerScenarios":"Passing a string to an int param; passing nil to `func(int)`; passing a struct where `*struct` is expected; mixing signed/unsigned ints in a way intLike conversion cannot bridge.","commonSituations":"FuncMap helpers whose signatures expect concrete types but the template supplies front-matter strings; nil optional values forwarded into typed params; refactoring parameter types.","solutions":["Convert in-template with the appropriate builtin (e.g. `int`, `string`) before calling.","Make the Go func accept interface{} or loose types and validate inside.","Guard nils: `{{with .V}}{{call .Fn .}}{{end}}`.","Align the call-site argument types to the declared parameter types."],"exampleFix":"// before\n{{call .Count \"5\"}}   // func(int) int\n\n// after\n{{call .Count (int \"5\")}}","handlingStrategy":"type-guard","validationCode":"// Coerce arg types before calling:\n//   {{call .Count (int .Qty)}}\n// Or make the Go func accept interface{} and validate internally.","typeGuard":"func matchesParam(fn interface{}, idx int, arg interface{}) bool {\n    ft := reflect.TypeOf(fn)\n    if ft.Kind() != reflect.Func { return false }\n    var pt reflect.Type\n    if ft.IsVariadic() && idx >= ft.NumIn()-1 {\n        pt = ft.In(ft.NumIn()-1).Elem()\n    } else {\n        pt = ft.In(idx)\n    }\n    av := reflect.ValueOf(arg)\n    if !av.IsValid() { return false }\n    return av.Type().AssignableTo(pt)\n}","tryCatchPattern":null,"preventionTips":["Coerce front-matter strings to numbers with int/float builtins.","Guard nils before passing into typed params.","Prefer (value, error) return funcs that validate internally."],"tags":["template","call","type-mismatch","text-template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}