{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/parser/metadecoders/decoder.go#L120-L156","documentation":"Thrown by Decoder.UnmarshalStringTo (parser/metadecoders/decoder.go:138) when the target type 'typ' is not one of the supported cases (string, map[string]any, hmaps.Params, []any, bool, int, int64, float64). The %T names the unsupported type. This function dispatches on the concrete Go type of the destination, so an arbitrary struct or pointer triggers the default branch.","triggerScenarios":"Calling UnmarshalStringTo(data, someStruct{}) or UnmarshalStringTo(data, &myType{}) where the target is not one of the eight supported scalar/collection types; passing a custom type alias that does not match any case.","commonSituations":"Programmatic misuse of the metadecoders API by plugin/theme authors; passing a struct pointer expecting reflection-based decoding (use UnmarshalTo for that).","solutions":["Pass one of the supported target types: string, map[string]any, hmaps.Params, []any, bool, int, int64, or float64.","For decoding into arbitrary structs, use Decoder.UnmarshalTo(data, format, &myStruct) instead of UnmarshalStringTo.","If a custom collection type is needed, decode into map[string]any first then convert."],"exampleFix":"// before\nvar s MyStruct\nv, err := dec.UnmarshalStringTo(raw, &s)\n\n// after\nv, err := dec.UnmarshalTo([]byte(raw), metadecoders.JSON, &s)","handlingStrategy":"type-guard","validationCode":"// Only pass supported target types to UnmarshalStringTo.\nfunc isSupportedStringTarget(typ any) bool {\n    switch typ.(type) {\n    case string, map[string]any, hmaps.Params, []any, bool, int, int64, float64:\n        return true\n    }\n    return false\n}","typeGuard":"func isSupportedStringTarget(typ any) bool {\n    switch typ.(type) {\n    case string, map[string]any, hmaps.Params, []any, bool, int, int64, float64:\n        return true\n    }\n    return false\n}","tryCatchPattern":"v, err := dec.UnmarshalStringTo(raw, target)\nif err != nil {\n    return fmt.Errorf(\"cannot unmarshal string into target: %w\", err)\n}","preventionTips":["Use UnmarshalTo for struct decoding; reserve UnmarshalStringTo for the eight supported scalar/collection types.","Document the supported set near call sites."],"tags":["metadecoders","type-mismatch","api-misuse","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}