{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/media/config.go#L186-L222","documentation":"When decoding the contentTypes config section, Hugo validates each key against the site's registered media types via types.GetByType. If a key doesn't match any known media type (built-in or user-defined under mediaTypes), decoding aborts with this error. This prevents silently ignoring a content-type configuration that could never take effect.","triggerScenarios":"A contentTypes map key in site config that is not a registered media type — e.g. [contentTypes.'text/markdown2'] or a key with a typo like 'text/mardown'. Also hit when a custom media type is referenced in contentTypes but was never declared under mediaTypes, so GetByType returns not-found.","commonSituations":"Typos in contentTypes keys; using a file extension ('md') instead of the MIME string ('text/markdown'); defining contentTypes for a custom type before/without adding it to mediaTypes; copying config between Hugo versions where a built-in type name changed.","solutions":["Correct the contentTypes key to an exact registered media type string, e.g. 'text/markdown', 'text/asciidoc', 'text/pandoc'.","If it's a custom type, declare it under [mediaTypes.'your/type'] first so it's registered before contentTypes is decoded.","Run 'hugo config' to inspect the effective mediaTypes list and match your key against it."],"exampleFix":"# before (hugo.toml)\n[contentTypes.\"markdown\"]\n\n# after\n[contentTypes.\"text/markdown\"]","handlingStrategy":"validation","validationCode":"// Check the media type is registered before referencing it in outputFormats\nif _, found := mediaTypesConfig[strings.ToLower(mt)]; !found {\n    return fmt.Errorf(\"media type %q not defined; add it to mediaTypes first\", mt)\n}","typeGuard":null,"tryCatchPattern":"if err := decodeConfig(cfg); err != nil {\n    if strings.Contains(err.Error(), \"unknown media type\") {\n        // report which outputFormat references an undefined media type\n    }\n    return err\n}","preventionTips":["Define custom media types under [mediaTypes] before referencing them in [outputFormats]","Reference media types exactly, case-insensitively matching the registered name","Run hugo config to inspect the effective mediaTypes list when adding output formats"],"tags":["hugo","config","content-types","media-types"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}