{"record":{"id":"e615194158115f6a","repo":"gohugoio/hugo","slug":"invalid-dictionary-call","errorCode":null,"errorMessage":"invalid dictionary call","messagePattern":"invalid dictionary call","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":162,"sourceCode":"\t\t\t\tstr.WriteString(valStr)\n\t\t\tdefault:\n\t\t\t\tstr.WriteString(valStr + d)\n\t\t\t}\n\t\t}\n\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"can't iterate over %T\", l)\n\t}\n\n\treturn str.String(), nil\n}\n\n// Dictionary creates a new map from the given parameters by\n// treating values as key-value pairs.  The number of values must be even.\n// The keys can be string slices, which will create the needed nested structure.\nfunc (ns *Namespace) Dictionary(values ...any) (map[string]any, error) {\n\tif len(values)%2 != 0 {\n\t\treturn nil, errors.New(\"invalid dictionary call\")\n\t}\n\n\troot := make(map[string]any)\n\n\tfor i := 0; i < len(values); i += 2 {\n\t\tdict := root\n\t\tvar key string\n\t\tswitch v := values[i].(type) {\n\t\tcase string:\n\t\t\tkey = v\n\t\tcase []string:\n\t\t\tfor i := range len(v) - 1 {\n\t\t\t\tkey = v[i]\n\t\t\t\tvar m map[string]any\n\t\t\t\tv, found := dict[key]\n\t\t\t\tif found {\n\t\t\t\t\tm = v.(map[string]any)\n\t\t\t\t} else {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/collections.go#L144-L180","documentation":"Dictionary (collections.go:160-163) pairs arguments as key,value,key,value... so the count must be even. An odd total leaves an orphan key with no value, which cannot form a map entry, so it is rejected up front.","triggerScenarios":"{{ dictionary \"a\" 1 \"b\" }} (3 args) - key \"b\" has no value; or any odd-length call.","commonSituations":"Adding a key and forgetting its value; trailing key from a generated/templated dict construction; copy-paste dropping one value.","solutions":["Count arguments and ensure they pair up evenly","Add the missing value for the trailing key","When generating dynamically, append a placeholder value for any unpaired key"],"exampleFix":"// before\n{{ dictionary \"a\" 1 \"b\" }}\n// after\n{{ dictionary \"a\" 1 \"b\" 2 }}","handlingStrategy":"validation","validationCode":"{{/* build the dict from a slice of pairs to guarantee even count */}}\n{{ $pairs := slice (slice \"a\" 1) (slice \"b\" 2) }}\n{{ $dict := newScratch }}\n{{ range $pairs }}{{ $dict.Set (index . 0) (index . 1) }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass key+value pairs; count must be even","When generating dynamically, append a placeholder for any unpaired key","Review copy-pasted dict calls for dropped values"],"tags":["hugo","go-template","collections","argument-validation","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}