{"record":{"id":"126e4be5d53d0913","repo":"gohugoio/hugo","slug":"complement-needs-at-least-two-arguments","errorCode":null,"errorMessage":"complement needs at least two arguments","messagePattern":"complement needs at least two arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/complement.go","lineNumber":34,"sourceCode":"import (\n\t\"errors\"\n\t\"fmt\"\n\t\"reflect\"\n\n\t\"github.com/gohugoio/hugo/common/hreflect\"\n)\n\n// Complement gives the elements in the last element of ls that are not in\n// any of the others.\n//\n// All elements of ls must be slices or arrays of comparable types.\n//\n// The reasoning behind this rather clumsy API is so we can do this in the templates:\n//\n//\t{{ $c := .Pages | complement $last4 }}\nfunc (ns *Namespace) Complement(ls ...any) (any, error) {\n\tif len(ls) < 2 {\n\t\treturn nil, errors.New(\"complement needs at least two arguments\")\n\t}\n\n\tuniverse := ls[len(ls)-1]\n\tas := ls[:len(ls)-1]\n\n\taset, err := collectIdentities(as...)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tv := reflect.ValueOf(universe)\n\tswitch v.Kind() {\n\tcase reflect.Array, reflect.Slice:\n\t\tsl := reflect.MakeSlice(v.Type(), 0, 0)\n\t\tfor i := range v.Len() {\n\t\t\tev, _ := hreflect.Indirect(v.Index(i))\n\t\t\tif _, found := aset[normalize(ev)]; !found {\n\t\t\t\tsl = reflect.Append(sl, ev)","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/complement.go#L16-L52","documentation":"Thrown by the Complement template function when fewer than 2 arguments are provided (complement.go:33). Complement treats all args except the last as 'subtrahend' sets and the last as the 'universe' to filter; with <2 args there is no universe to subtract from, so it is rejected immediately.","triggerScenarios":"Calling {{ complement }} (no args) or {{ complement $only }} (one arg). In templates the pipe form {{ .Pages | complement $last4 }} supplies two args; forgetting the piped left-hand operand or calling with a literal single arg triggers it.","commonSituations":"Refactoring a pipeline so .Pages no longer flows in; using complement as a unary filter by mistake; removing the 'universe' argument.","solutions":["Provide at least two arguments: a subtraction set and a universe, e.g. {{ $all | complement $exclude }}.","If you only have one set and want it unchanged, do not call complement at all.","Verify the pipe: {{ .Pages | complement $last4 }} yields args = [$last4, .Pages]."],"exampleFix":"// before\n{{ complement $exclude }}\n// after\n{{ .Pages | complement $exclude }}","handlingStrategy":"validation","validationCode":"{{/* complement needs >=2 args; pipe form supplies them */}}\n{{ .Pages | complement $exclude }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide a universe AND at least one subtraction set.","Use the pipe form {{ $all | complement $exclude }} to guarantee two args.","Do not call complement with a single argument."],"tags":["hugo","template","collections","complement","arity","argument-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}