{"record":{"id":"edde599492bdf5ab","repo":"gohugoio/hugo","slug":"unknown-media-type-q","errorCode":null,"errorMessage":"unknown media type %q","messagePattern":"unknown media type %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"media/config.go","lineNumber":204,"sourceCode":"\t\t}\n\t\tif len(m) == 0 {\n\t\t\ts = defaultContentTypesConfig\n\t\t} else {\n\t\t\ts = make(map[string]ContentTypeConfig)\n\t\t\tm = hmaps.CleanConfigStringMap(m)\n\t\t\tfor k, v := range m {\n\t\t\t\tvar ctc ContentTypeConfig\n\t\t\t\tif err := mapstructure.WeakDecode(v, &ctc); err != nil {\n\t\t\t\t\treturn c, nil, err\n\t\t\t\t}\n\t\t\t\ts[k] = ctc\n\t\t\t}\n\t\t}\n\n\t\tfor k := range s {\n\t\t\tmediaType, found := types.GetByType(k)\n\t\t\tif !found {\n\t\t\t\treturn c, nil, fmt.Errorf(\"unknown media type %q\", k)\n\t\t\t}\n\t\t\tc.types = append(c.types, mediaType)\n\t\t}\n\n\t\tc.init(types)\n\n\t\treturn c, s, nil\n\t}\n\n\tns, err := config.DecodeNamespace[map[string]ContentTypeConfig](in, buildConfig)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode media types: %w\", err)\n\t}\n\treturn ns, nil\n}\n\n// DecodeTypes decodes the given map of media types.\nfunc DecodeTypes(in map[string]any) (*config.ConfigNamespace[map[string]MediaTypeConfig, Types], error) {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/media/config.go#L186-L222","documentation":"Returned by DecodeContentTypes when a key in the [mediaTypes]-derived content types map does not resolve to any known media type via types.GetByType(k). Hugo requires every content type referenced to exist in the decoded media Types set; an unknown type cannot be associated with content handling.","triggerScenarios":"Listing a content type key (a MIME like 'text/myext' or a sub-type) under the content types config that is not declared in the media types config. Fires during media.DecodeContentTypes at startup.","commonSituations":"Defining a custom output format / content type but forgetting to also declare it under [mediaTypes]; typo in the MIME string; renaming a media type in [mediaTypes] but not updating the content types reference; copy-pasting a format config that assumes a media type that was removed.","solutions":["Add the missing media type under [mediaTypes] with the same key that appears in the content types config.","Fix typos: the key must be exactly MainType/SubType (e.g. 'text/markdown').","If the content type is no longer needed, remove it from the content types config."],"exampleFix":"# before: content type referenced but media type missing\n[outputFormats.MyFormat]\nmediaType = \"text/myfmt\"\n# no [mediaTypes] entry\n\n# after\n[mediaTypes]\n[mediaTypes.\"text/myfmt\"]\nsuffixes = [\"myfmt\"]","handlingStrategy":"validation","validationCode":"// Ensure each content type key resolves before decoding.\nfunc validateContentKeys(in map[string]any, known media.Types) error {\n    for k := range in {\n        if _, ok := known.GetByType(k); !ok {\n            return fmt.Errorf(\"content type %q is not a declared media type\", k)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"_, err := media.DecodeContentTypes(in, types)\nif err != nil && strings.Contains(err.Error(), \"unknown media type\") {\n    // point user to the missing [mediaTypes] entry\n}","preventionTips":["Declare a media type in [mediaTypes] before referencing it as a content type or output format.","Keep [mediaTypes] and [outputFormats] config blocks in the same file for easy cross-checking."],"tags":["media-types","config","validation","content-types"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}