{"id":"5f99470d0f4648f2","repo":"gohugoio/hugo","slug":"unable-to-cast-v-of-type-t-to-map-string-inte","errorCode":null,"errorMessage":"unable to cast %#v of type %T to []map[string]interface{}","messagePattern":"unable to cast %#v of type %T to \\[\\]map\\[string\\]interface(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/hmaps/maps.go","lineNumber":112,"sourceCode":"// ToSliceStringMap converts in to []map[string]interface{}.\nfunc ToSliceStringMap(in any) ([]map[string]any, error) {\n\tswitch v := in.(type) {\n\tcase []map[string]any:\n\t\treturn v, nil\n\tcase Params:\n\t\treturn []map[string]any{v}, nil\n\tcase map[string]any:\n\t\treturn []map[string]any{v}, nil\n\tcase []any:\n\t\tvar s []map[string]any\n\t\tfor _, entry := range v {\n\t\t\tif vv, ok := entry.(map[string]any); ok {\n\t\t\t\ts = append(s, vv)\n\t\t\t}\n\t\t}\n\t\treturn s, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unable to cast %#v of type %T to []map[string]interface{}\", in, in)\n\t}\n}\n\n// LookupEqualFold finds key in m with case insensitive equality checks.\nfunc LookupEqualFold[T any | string](m map[string]T, key string) (T, string, bool) {\n\tif v, found := m[key]; found {\n\t\treturn v, key, true\n\t}\n\tfor k, v := range m {\n\t\tif strings.EqualFold(k, key) {\n\t\t\treturn v, k, true\n\t\t}\n\t}\n\tvar s T\n\treturn s, \"\", false\n}\n\n// MergeShallow merges src into dst, but only if the key does not already exist in dst.","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/common/hmaps/maps.go#L94-L130","documentation":"hmaps.ToSliceStringMap converts an arbitrary value into []map[string]interface{}. It accepts []map[string]any, Params, map[string]any, or []any (keeping only map entries); every other concrete type hits the default case and returns this error with the value and its Go type. Hugo uses it where config or front matter must be a list of maps (e.g. lists of objects).","triggerScenarios":"Passing a scalar, a string, a []string, or a map with non-string keys where Hugo expects a slice of maps — e.g. a config section like `[[menu.main]]`-style structures, cascade lists, or template code calling this converter on a param that is a plain string or list of strings.","commonSituations":"YAML/TOML front matter or site config where a key expected to be a list of objects is written as a plain list of strings or a single string (e.g. `outputs` vs a list of tables); data files with map[interface{}]interface{} keys from older YAML; passing the wrong param to a function expecting map slices.","solutions":["Fix the config/front matter shape: the value must be a list of maps (in YAML, a list of `key: value` blocks; in TOML, [[double-bracket]] tables).","Print the offending value with `printf \"%#v\"` or `jsonify` to see its actual type, then adjust the source.","If keys are non-string (old YAML), quote them or restructure so YAML produces map[string]interface{}."],"exampleFix":"# before (front matter)\nresources: [\"image.png\", \"doc.pdf\"]\n\n# after\nresources:\n  - src: image.png\n  - src: doc.pdf","handlingStrategy":"type-guard","validationCode":"// Ensure the value is a slice of maps before conversion\nif _, ok := v.([]map[string]any); !ok {\n\tif s, ok := v.([]any); ok { /* check each element is a map */ _ = s }\n}","typeGuard":"func isSliceOfMaps(v any) bool {\n\tswitch s := v.(type) {\n\tcase []map[string]any:\n\t\treturn true\n\tcase []any:\n\t\tfor _, e := range s {\n\t\t\tif _, ok := e.(map[string]any); !ok { return false }\n\t\t}\n\t\treturn len(s) > 0\n\t}\n\treturn false\n}","tryCatchPattern":"m, err := hmaps.ToSliceStringMap(v)\nif err != nil {\n\t// value isn't a list of objects — report the actual type from the error\n}","preventionTips":["Ensure YAML/TOML/JSON data files define a list of objects (e.g. `- name: x`), not a scalar or a single map.","Check front-matter shape: a field expected to be a list of maps must not be a plain string.","Probe with reflect.Kind or a type switch before calling map-conversion helpers."],"tags":["hugo","config","front-matter","type-cast","maps"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}