{"id":"13d302d890e692a1","repo":"gohugoio/hugo","slug":"unmarshal-of-format-q-is-not-supported","errorCode":null,"errorMessage":"unmarshal of format %q is not supported","messagePattern":"unmarshal of format %q is not supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"parser/metadecoders/decoder.go","lineNumber":325,"sourceCode":"\t\t\t}\n\t\t\txmlValue = mapValue\n\t\t}\n\n\t\tswitch v := v.(type) {\n\t\tcase *map[string]any:\n\t\t\t*v = xmlValue\n\t\tcase *any:\n\t\t\t*v = xmlValue\n\t\t}\n\tcase TOML:\n\t\terr = toml.Unmarshal(data, v)\n\tcase YAML:\n\t\treturn UnmarshalYaml(data, v)\n\tcase CSV:\n\t\treturn d.unmarshalCSV(data, v)\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unmarshal of format %q is not supported\", f)\n\t}\n\n\tif err == nil {\n\t\treturn nil\n\t}\n\n\treturn toFileError(f, data, fmt.Errorf(\"unmarshal failed: %w\", err))\n}\n\nfunc (d Decoder) unmarshalCSV(data []byte, v any) error {\n\tr := csv.NewReader(bytes.NewReader(data))\n\tr.Comma = d.Delimiter\n\tr.Comment = d.Comment\n\tr.LazyQuotes = d.LazyQuotes\n\n\trecords, err := r.ReadAll()\n\tif err != nil {\n\t\treturn err","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/parser/metadecoders/decoder.go#L307-L343","documentation":"Hugo's metadecoders.Decoder.UnmarshalTo switches on the Format value (ORG, JSON, XML, TOML, YAML, CSV) and returns this error from the default branch when the supplied Format matches none of the supported cases. It exists because Format is derived from a file extension or MIME type upstream, and an unrecognized or zero-value Format must fail fast rather than silently produce empty data.","triggerScenarios":"Calling Unmarshal/UnmarshalTo with an empty Format (the zero value produced by FormatFromString on an unknown extension), or with a Format constant that has no decode branch. Typically reached via transform.Unmarshal in templates, resources.Get + transform.Unmarshal on a file whose extension isn't json/toml/yaml/yml/xml/csv/org, or data-file loading where the format could not be inferred.","commonSituations":"Templates piping an unsupported resource (e.g. a .txt, .md, or extensionless remote resource) into transform.Unmarshal; remote resources fetched with resources.GetRemote whose Content-Type/extension doesn't map to a known format so FormatFromString returns \"\"; typoed extensions like .yamll; expecting Hugo to unmarshal formats it only marshals.","solutions":["Check the file extension or remote Content-Type: it must map to json, toml, yaml/yml, xml, csv, or org.","When using resources.GetRemote, pass an explicit mediaType option or rename/copy the resource with a proper extension before transform.Unmarshal.","If constructing a Decoder in Go code, pass a valid metadecoders.Format constant, not the zero value from a failed FormatFromString lookup."],"exampleFix":"// before\n{{ $data := resources.GetRemote \"https://example.com/api\" | transform.Unmarshal }}\n// after\n{{ $data := resources.GetRemote \"https://example.com/api\" (dict \"headers\" (dict \"Accept\" \"application/json\")) | transform.Unmarshal (dict \"format\" \"json\") }}","handlingStrategy":"validation","validationCode":"// check the format is one of the supported set before calling Unmarshal\nvar supported = map[metadecoders.Format]bool{metadecoders.JSON: true, metadecoders.YAML: true, metadecoders.TOML: true, metadecoders.CSV: true, metadecoders.XML: true, metadecoders.ORG: true}\nif !supported[format] {\n    return fmt.Errorf(\"format %q not supported\", format)\n}","typeGuard":"func isSupportedFormat(f metadecoders.Format) bool {\n    switch f {\n    case metadecoders.JSON, metadecoders.YAML, metadecoders.TOML, metadecoders.CSV, metadecoders.XML, metadecoders.ORG:\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err := decoder.UnmarshalTo(data, format, &v); err != nil {\n    if strings.Contains(err.Error(), \"is not supported\") {\n        // fall back to asking the user for a valid format\n    }\n    return err\n}","preventionTips":["Derive the Format with metadecoders.FormatFromString/FormatFromContentType instead of constructing it by hand","Check FormatFromString returned a non-empty Format (unknown extensions yield \"\") before decoding","Keep an allowlist of formats your app accepts and validate file extensions at intake"],"tags":["hugo","unmarshal","data-format","templates"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}