{"record":{"id":"943a3c6ae15c4006","repo":"gohugoio/hugo","slug":"failed-to-decode-media-types-w","errorCode":null,"errorMessage":"failed to decode media types: %w","messagePattern":"failed to decode media types: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"media/config.go","lineNumber":216,"sourceCode":"\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) {\n\tbuildConfig := func(v any) (Types, any, error) {\n\t\tm, err := hmaps.ToStringMapE(v)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\t\tif m == nil {\n\t\t\tm = map[string]any{}\n\t\t}\n\t\tm = hmaps.CleanConfigStringMap(m)\n\t\t// Merge with defaults.\n\t\thmaps.MergeShallow(m, defaultMediaTypesConfig)\n","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/media/config.go#L198-L234","documentation":"Returned by DecodeContentTypes when config.DecodeNamespace fails while building ContentTypes. Wraps the inner error with %w (unwrappable). The inner failure is usually the 'unknown media type %q' error (447) or a mapstructure decode error on a ContentTypeConfig value, but any failure in the buildConfig closure bubbles up here.","triggerScenarios":"Calling DecodeContentTypes with a content types config map whose build step fails: unknown media type reference, malformed mapstructure values, or a non-map input passed as the config source. Fires during Hugo config load.","commonSituations":"Same as 447 plus structurally invalid config: a content type entry whose value is not a map (e.g. a bare string), or a media type referenced before it is defined because the media types decode ran against a stale/empty Types set.","solutions":["Read the wrapped (%w) error message to identify the specific cause (unknown type vs decode error).","Ensure every referenced content type key exists in the decoded media Types.","Make sure each content type entry is a table/map, not a scalar.","Validate the full [mediaTypes] + content types config together with `hugo config`."],"exampleFix":"# before\n[mediaTypes]\n[mediaTypes.\"text/markdown\"]\nsuffixes = [\"md\"]\n# content type references text/md (typo)\n\n# after\n[mediaTypes]\n[mediaTypes.\"text/markdown\"]\nsuffixes = [\"md\"]\n# reference matches exactly: text/markdown","handlingStrategy":"try-catch","validationCode":"// Pre-check that all content type values are maps and keys are known MIMEs.\nfunc preflightContentTypes(in map[string]any) error {\n    for k, v := range in {\n        if _, ok := v.(map[string]any); !ok {\n            return fmt.Errorf(\"content type %q must be a map\", k)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"ns, err := media.DecodeContentTypes(in, types)\nif err != nil {\n    // err wraps the concrete cause; unwrap for messaging\n    return fmt.Errorf(\"decode content types: %w\", err)\n}","preventionTips":["Treat any wrapped error here as actionable; read the unwrapped cause.","Run `hugo config` after editing media/output config to validate early."],"tags":["media-types","config","decode","content-types"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}