{"id":"369bc58273f1bac4","repo":"gohugoio/hugo","slug":"merge-requires-at-least-two-parameters","errorCode":null,"errorMessage":"merge requires at least two parameters","messagePattern":"merge requires at least two parameters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/merge.go","lineNumber":32,"sourceCode":"package collections\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n\n\t\"github.com/gohugoio/hugo/common/hmaps\"\n\t\"github.com/gohugoio/hugo/common/hreflect\"\n)\n\n// Merge creates a copy of the final parameter in params and merges the preceding\n// parameters into it in reverse order.\n//\n// Currently only maps are supported. Key handling is case insensitive.\nfunc (ns *Namespace) Merge(params ...any) (any, error) {\n\tif len(params) < 2 {\n\t\treturn nil, errors.New(\"merge requires at least two parameters\")\n\t}\n\n\tvar err error\n\tresult := params[len(params)-1]\n\n\tfor i := len(params) - 2; i >= 0; i-- {\n\t\tresult, err = ns.merge(params[i], result)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\treturn result, nil\n}\n\n// merge creates a copy of dst and merges src into it.\nfunc (ns *Namespace) merge(src, dst any) (any, error) {\n\tvdst, vsrc := reflect.ValueOf(dst), reflect.ValueOf(src)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/merge.go#L14-L50","documentation":"`collections.Merge` deep-merges two or more maps, treating the last parameter as the base and merging preceding parameters into it in reverse order. Since merging is only meaningful with at least a source and a destination, Hugo returns this error when the function is called with fewer than two parameters.","triggerScenarios":"Calling `{{ merge $onlyOneMap }}` or `{{ merge }}` in a template; also a pipeline like `{{ $m | merge }}` where the pipe supplies the sole argument.","commonSituations":"Refactoring that removed one side of the merge; conditionally-built argument lists where a `with`/`if` left only one map in scope; confusion with `dict` (which builds a map from key/value pairs) versus `merge` (which combines existing maps).","solutions":["Pass at least two maps: `{{ $merged := merge $defaults $overrides }}` (later maps in the call are merged into the last one; leftmost keys win).","If one side may be empty, pass an empty dict explicitly: `{{ merge (default dict $maybe) $base }}`.","If you intended to construct a map rather than combine maps, use `dict` instead."],"exampleFix":"<!-- before -->\n{{ $opts := merge .Params }}\n<!-- after -->\n{{ $opts := merge site.Params.defaults .Params }}","handlingStrategy":"validation","validationCode":"{{ $maps := slice $m1 $m2 }}\n{{ if ge (len $maps) 2 }}{{ $merged := merge $m1 $m2 }}{{ end }}","typeGuard":null,"tryCatchPattern":"{{ with try (merge $m1) }}{{ with .Err }}{{ warnf \"merge needs >=2 maps: %s\" . }}{{ else }}{{ .Value }}{{ end }}{{ end }}","preventionTips":["Always call merge with at least two map arguments; a single map has nothing to merge","When piping (`$m1 | merge $m2`), remember the piped value counts as the final argument — verify total is ≥2","If merging a dynamic list of maps, guard `len` ≥ 2 and fall back to the sole map yourself only if that behavior is explicitly desired"],"tags":["hugo","collections","templates","maps"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}