{"id":"6c6fddb8d8669dbd","repo":"gohugoio/hugo","slug":"unmarshal-t-not-supported","errorCode":null,"errorMessage":"unmarshal: %T not supported","messagePattern":"unmarshal: %T not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"parser/metadecoders/decoder.go","lineNumber":138,"sourceCode":"\tswitch typ.(type) {\n\tcase string:\n\t\treturn data, nil\n\tcase map[string]any, hmaps.Params:\n\t\tformat := d.FormatFromContentString(data)\n\t\treturn d.UnmarshalToMap([]byte(data), format)\n\tcase []any:\n\t\t// A standalone slice. Let YAML handle it.\n\t\treturn d.Unmarshal([]byte(data), YAML)\n\tcase bool:\n\t\treturn cast.ToBoolE(data)\n\tcase int:\n\t\treturn cast.ToIntE(data)\n\tcase int64:\n\t\treturn cast.ToInt64E(data)\n\tcase float64:\n\t\treturn cast.ToFloat64E(data)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unmarshal: %T not supported\", typ)\n\t}\n}\n\n// Unmarshal will unmarshall data in format f into an interface{}.\n// This is what's needed for Hugo's /data handling.\nfunc (d Decoder) Unmarshal(data []byte, f Format) (any, error) {\n\tif len(data) == 0 {\n\t\tswitch f {\n\t\tcase CSV:\n\t\t\tswitch d.TargetType {\n\t\t\tcase \"map\":\n\t\t\t\treturn make(map[string]any), nil\n\t\t\tcase \"slice\":\n\t\t\t\treturn make([][]string, 0), nil\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"invalid targetType: expected either slice or map, received %s\", d.TargetType)\n\t\t\t}\n\t\tdefault:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/parser/metadecoders/decoder.go#L120-L156","documentation":"Decoder.UnmarshalStringTo converts a string into a value of the same type as the provided prototype `typ`, but it only supports string, map (map[string]any / maps.Params), []any, bool, int, int64, and float64. Any other prototype type falls through to the default case and returns this error with the Go type name, because Hugo has no defined conversion for it.","triggerScenarios":"Internal callers (e.g. `transform.Unmarshal` with a typed default, front matter/param coercion paths) passing a prototype whose dynamic type is outside the supported set — e.g. a time.Time, a struct, uint, float32, or a typed slice like []string instead of []any.","commonSituations":"Template authors hitting it indirectly via `transform.Unmarshal` or param handling when a default/target value has an unexpected type; Hugo version changes shifting which types flow into this coercion; custom output/data pipelines producing typed values Hugo tries to unmarshal a string into.","solutions":["Change the target/default value to one of the supported types — use a plain map, []any, string, bool, int, int64, or float64 as the prototype.","In templates, unmarshal to a generic value first (`transform.Unmarshal $str`) and then cast (`int`, `float`, `time.AsTime`) instead of expecting a typed result directly.","If it appears after a Hugo upgrade, check the release notes for changes to the config/param whose type is named in the %T output and adjust its declared type."],"exampleFix":"{{/* before: expecting a typed value Hugo can't produce */}}\n{{ $v := transform.Unmarshal $s }}{{/* target type unsupported upstream */}}\n\n{{/* after: unmarshal generically, then cast */}}\n{{ $v := transform.Unmarshal $s }}\n{{ $n := int $v }}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Only pass string or []byte data to Unmarshal\nfunc unmarshalable(v any) bool {\n    switch v.(type) {\n    case string, []byte:\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"not supported\") {\n    // the input was already-decoded data or a wrong type; convert to string first\n}","preventionTips":["In templates, only call `transform.Unmarshal` on strings/resources, not on maps/slices that are already decoded","Guard with `{{ if reflect.IsMap . }}` (already decoded) before attempting Unmarshal","Convert numeric or other types to string explicitly before unmarshalling"],"tags":["hugo","unmarshal","type-conversion","templates"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}