{"record":{"id":"0eeb5a114e22f537","repo":"gohugoio/hugo","slug":"requires-at-least-2-arguments","errorCode":null,"errorMessage":"requires at least 2 arguments","messagePattern":"requires at least 2 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/strings.go","lineNumber":265,"sourceCode":"\n\tif len(limit) == 0 {\n\t\treturn strings.ReplaceAll(ss, so, sn), nil\n\t}\n\n\tlim, err := cast.ToIntE(limit[0])\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn strings.Replace(ss, so, sn, lim), nil\n}\n\n// ReplacePairs returns a copy of a string with multiple replacements performed\n// in a single pass. The last argument is the source string. Preceding arguments\n// are old/new string pairs, either as a slice or as individual arguments.\nfunc (ns *Namespace) ReplacePairs(args ...any) (string, error) {\n\tif len(args) < 2 {\n\t\treturn \"\", fmt.Errorf(\"requires at least 2 arguments\")\n\t}\n\n\tss, err := cast.ToStringE(args[len(args)-1])\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tvar p []string\n\tif len(args) == 2 {\n\t\t// slice form: ReplacePairs (slice \"a\" \"b\") \"s\"\n\t\tif !hreflect.IsSlice(args[0]) {\n\t\t\treturn \"\", fmt.Errorf(\"with 2 arguments, the first must be a slice of replacement pairs, got %T\", args[0])\n\t\t}\n\t\tp, err = cast.ToStringSliceE(args[0])\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/strings.go#L247-L283","documentation":"Thrown by strings.ReplacePairs when fewer than 2 arguments are supplied. ReplacePairs needs at least a replacement spec (slice or one pair) and the source string; the last arg is always the source.","triggerScenarios":"Calling {{ strings.ReplacePairs }} or {{ strings.ReplacePairs $s }} with zero or one argument. Both forms (inline pairs or slice) require the source string as the last positional argument.","commonSituations":"Forgetting the source string, calling with no args by mistake, or assuming ReplacePairs takes a map argument as a single value.","solutions":["Provide at least 2 arguments ending with the source string.","Use the slice form: strings.ReplacePairs (slice \"a\" \"b\") $s.","Use the inline form: strings.ReplacePairs \"a\" \"b\" $s.","Count arguments in the template call."],"exampleFix":"// before:\n{{ strings.ReplacePairs $s }}\n// after (inline pair + source):\n{{ strings.ReplacePairs \"a\" \"b\" $s }}","handlingStrategy":"validation","validationCode":"{{ if ge (len $args) 2 }}{{ strings.ReplacePairs $args... }}{{ else }}{{ warnf \"ReplacePairs needs >=2 args\" }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always end the call with the source string as the last argument.","Use the slice form when pairs are dynamic.","Count arguments before invoking."],"tags":["strings","replacepairs","argument-count","template"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}