{"id":"7c81c4b3611da293","repo":"gohugoio/hugo","slug":"mime-q-not-supported-7c81c4","errorCode":null,"errorMessage":"MIME %q not supported","messagePattern":"MIME %q not supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/unmarshal.go","lineNumber":84,"sourceCode":"\t\tif key == \"\" {\n\t\t\treturn nil, errors.New(\"no Key set in Resource\")\n\t\t}\n\n\t\tif decoder != metadecoders.Default {\n\t\t\tkey += decoder.OptionsKey()\n\t\t}\n\n\t\tv, err := ns.cacheUnmarshal.GetOrCreate(key, func(string) (*resources.StaleValue[any], error) {\n\t\t\tvar f metadecoders.Format\n\t\t\tif decoder.Format != \"\" {\n\t\t\t\tf = metadecoders.FormatFromString(decoder.Format)\n\t\t\t\tif f == \"\" {\n\t\t\t\t\treturn nil, fmt.Errorf(\"format %q not supported\", decoder.Format)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tf = metadecoders.FormatFromStrings(r.MediaType().Suffixes()...)\n\t\t\t\tif f == \"\" {\n\t\t\t\t\treturn nil, fmt.Errorf(\"MIME %q not supported\", r.MediaType())\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treader, err := r.ReadSeekCloser()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tdefer reader.Close()\n\n\t\t\tb, err := io.ReadAll(reader)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\tv, err := decoder.Unmarshal(b, f)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/transform/unmarshal.go#L66-L102","documentation":"Hugo's `transform.Unmarshal` template function was passed a Resource whose media type has no suffix mapping to a supported metadecoder format (JSON, TOML, YAML, CSV, XML). When no explicit `format` option is given, Hugo derives the format from the resource's MIME type suffixes via `metadecoders.FormatFromStrings`; if that yields nothing, this error is returned with the offending MIME type.","triggerScenarios":"Calling `{{ $data := resources.Get \"file.ext\" | transform.Unmarshal }}` (or `unmarshal`) on a resource whose media type (e.g. text/plain, image/png, application/octet-stream) doesn't map to json/toml/yaml/csv/xml, without passing an options map containing `format`.","commonSituations":"Fetching remote data with `resources.GetRemote` where the server returns a generic Content-Type like text/plain or application/octet-stream for a JSON/YAML payload; unmarshaling files with nonstandard extensions (.conf, .txt); custom mediaTypes config missing the needed suffix.","solutions":["Pass the format explicitly: `transform.Unmarshal (dict \"format\" \"json\") $resource`.","For remote resources, check the server's Content-Type header or rename/serve the file with a proper extension.","Add the suffix to a supported media type in your site's `mediaTypes` configuration.","Confirm the data is actually one of json, toml, yaml, csv, or xml — other formats are unsupported."],"exampleFix":"{{/* before */}}\n{{ $data := resources.GetRemote $url | transform.Unmarshal }}\n{{/* after */}}\n{{ $data := resources.GetRemote $url | transform.Unmarshal (dict \"format\" \"json\") }}","handlingStrategy":"validation","validationCode":"{{ $supported := slice \"application/json\" \"application/toml\" \"application/yaml\" \"application/xml\" \"text/csv\" }}\n{{ $r := resources.Get \"data/file.json\" }}\n{{ if in $supported $r.MediaType.Type }}\n  {{ $data := $r | transform.Unmarshal }}\n{{ end }}","typeGuard":null,"tryCatchPattern":"{{ $data := \"\" }}\n{{ with try (transform.Unmarshal $r) }}\n  {{ with .Err }}{{ warnf \"unmarshal failed: %s\" . }}{{ else }}{{ $data = .Value }}{{ end }}\n{{ end }}","preventionTips":["Check the resource's .MediaType before calling transform.Unmarshal","Only fetch remote resources whose Content-Type is JSON/TOML/YAML/XML/CSV","For remote APIs that return generic types (e.g. text/plain), pass the format explicitly via the options map: transform.Unmarshal (dict \"delimiter\" \",\") or ensure the URL ends with a known extension"],"tags":["hugo","templates","unmarshal","media-type"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}