{"record":{"id":"fb8d7bda69229d3f","repo":"gohugoio/hugo","slug":"wrong-number-of-args-for-default-want-2-got-d","errorCode":null,"errorMessage":"wrong number of args for default: want 2 got %d","messagePattern":"wrong number of args for default: want 2 got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/compare/compare.go","lineNumber":57,"sourceCode":"\tloc *time.Location\n\t// Enable to do case insensitive string compares.\n\tcaseInsensitive bool\n}\n\n// Default checks whether a givenv is set and returns the default value defaultv if it\n// is not.  \"Set\" in this context means non-zero for numeric types and times;\n// non-zero length for strings, arrays, slices, and maps;\n// any boolean or struct value; or non-nil for any other types.\nfunc (*Namespace) Default(defaultv any, givenv ...any) (any, error) {\n\t// given is variadic because the following construct will not pass a piped\n\t// argument when the key is missing:  {{ index . \"key\" | default \"foo\" }}\n\t// The Go template will complain that we got 1 argument when we expected 2.\n\n\tif len(givenv) == 0 {\n\t\treturn defaultv, nil\n\t}\n\tif len(givenv) != 1 {\n\t\treturn nil, fmt.Errorf(\"wrong number of args for default: want 2 got %d\", len(givenv)+1)\n\t}\n\n\tg := reflect.ValueOf(givenv[0])\n\tif !g.IsValid() {\n\t\treturn defaultv, nil\n\t}\n\n\tset := false\n\n\tswitch g.Kind() {\n\tcase reflect.Bool:\n\t\tset = true\n\tcase reflect.String, reflect.Array, reflect.Slice, reflect.Map:\n\t\tset = g.Len() != 0\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\tset = g.Int() != 0\n\tcase reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:\n\t\tset = g.Uint() != 0","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/compare/compare.go#L39-L75","documentation":"`compare.Default` (compare.go:48-58) is variadic: `Default(defaultv any, givenv ...any)`. It accepts zero or one given value (zero is the piped-missing case at line 53). If `len(givenv)` is greater than 1, it returns this error reporting the total count (`len(givenv)+1`). Hugo only supports one value to test against the default.","triggerScenarios":"`{{ default \"a\" \"b\" \"c\" }}` passing two given values; `{{ \"x\" | default \"a\" \"b\" }}` combining a pipe with extra positional args.","commonSituations":"Author treats `default` as a multi-arg coalesce/first-non-empty; leftover args from refactoring; confusing `default` with `cond`/`or`.","solutions":["Pass exactly one given value: `{{ default \"a\" \"b\" }}`.","For a multi-value fallback chain, nest `default` calls or use `or`: `{{ or $a $b $c $fallback }}`.","Remove stray piped + positional argument combinations."],"exampleFix":"// before\n{{ default \"a\" \"b\" \"c\" }}\n// after\n{{ default \"a\" \"b\" }}\n{{/* or for chaining */}}\n{{ or $b $c \"a\" }}","handlingStrategy":"validation","validationCode":"{{/* default takes exactly one optional given value; chain with or for more */}}\n{{ default \"a\" $maybe }}\n{{ or $a $b $c \"fallback\" }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember `default` is not a coalesce — use `or` for multi-value fallback.","Avoid mixing a pipe with positional args to `default`.","Check arg count when refactoring template expressions."],"tags":["hugo","go-templates","compare","default","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}