{"id":"fad4182b78b85c1a","repo":"gohugoio/hugo","slug":"invalid-output-format-configuration-wrong-type-fo","errorCode":null,"errorMessage":"invalid output format configuration; wrong type for media type, expected string (e.g. text/html), got %T","messagePattern":"invalid output format configuration; wrong type for media type, expected string \\(e\\.g\\. text/html\\), got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/config.go","lineNumber":124,"sourceCode":"\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif strings.EqualFold(keyStr, \"mediaType\") {\n\t\t\t\t\t\t// If mediaType is a string, look it up and replace it\n\t\t\t\t\t\t// in the map.\n\t\t\t\t\t\tvv := dataVal.MapIndex(key)\n\t\t\t\t\t\tvvi := vv.Interface()\n\n\t\t\t\t\t\tswitch vviv := vvi.(type) {\n\t\t\t\t\t\tcase media.Type:\n\t\t\t\t\t\t// OK\n\t\t\t\t\t\tcase string:\n\t\t\t\t\t\t\tmediaType, found := mediaTypes.GetByType(vviv)\n\t\t\t\t\t\t\tif !found {\n\t\t\t\t\t\t\t\treturn c, fmt.Errorf(\"media type %q not found\", vviv)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdataVal.SetMapIndex(key, reflect.ValueOf(mediaType))\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn nil, fmt.Errorf(\"invalid output format configuration; wrong type for media type, expected string (e.g. text/html), got %T\", vvi)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn c, nil\n\t\t},\n\t}\n\n\tdecoder, err := mapstructure.NewDecoder(config)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err = decoder.Decode(input); err != nil {\n\t\treturn fmt.Errorf(\"failed to decode output format configuration: %w\", err)\n\t}\n\n\treturn nil","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/output/config.go#L106-L142","documentation":"Raised by the same decode hook (output/config.go:124) when an output format's mediaType value is neither an already-resolved media.Type nor a string. The hook only knows how to look up string values like \"text/html\"; a map, number, list, or other structure is a malformed configuration and is rejected with the offending Go type.","triggerScenarios":"Decoding [outputFormats] config where mediaType is given as a table/map (e.g. an inline object with type/suffixes fields), a list, or a number instead of a plain \"type/subtype\" string.","commonSituations":"Confusing the [mediaTypes] definition shape (which is a table with suffixes) with the outputFormats reference (which must be a string); YAML config where mediaType is accidentally nested as a mapping; programmatic config generation emitting an object instead of a string.","solutions":["Set mediaType to a plain string such as \"text/html\" in the output format definition.","Move any suffix/structural configuration into a [mediaTypes.'<type>'] block and reference it by name from the output format.","Validate generated config (YAML/JSON) to ensure mediaType serializes as a scalar string."],"exampleFix":"# before (yaml)\noutputFormats:\n  MyFormat:\n    mediaType:\n      type: text/html\n\n# after\noutputFormats:\n  MyFormat:\n    mediaType: text/html","handlingStrategy":"type-guard","validationCode":"// In outputFormats config, mediaType must be a plain string:\n[outputFormats.myformat]\n  mediaType = 'text/html'   # correct\n# mediaType = { type = 'text/html' }  # wrong: table/map, will fail","typeGuard":"func validMediaTypeValue(v any) bool { _, ok := v.(string); return ok }","tryCatchPattern":null,"preventionTips":["Set `mediaType` as a string like `text/html`, never a nested table/map object","When generating config programmatically (JSON/YAML), ensure serializers don't emit objects for mediaType","Validate config with a dry build after editing outputFormats"],"tags":["hugo","configuration","output-formats","type-error"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}