{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/output/config.go#L106-L142","documentation":"Thrown in the mapstructure decode hook (output/config.go:124) when a custom output format's 'mediaType' field is present but is neither a string nor an already-resolved media.Type. The %T shows the offending type. Hugo expects mediaType to be a string like \"text/html\".","triggerScenarios":"Setting mediaType to a number (mediaType = 123), a boolean, an array (mediaType = [\"text/html\"]), or a nested map; WeaklyTypedInput is on but does not cover the type mismatch for this specific non-string scalar.","commonSituations":"TOML/YAML config where mediaType is accidentally quoted as a list or left as a bare number; tooling that injects mediaType from a variable of the wrong type; migrating config and dropping the surrounding quotes incorrectly.","solutions":["Set mediaType to a plain string: mediaType = \"text/html\".","If the value comes from a template or script, ensure it is serialized as a string scalar.","Run hugo config to inspect the resolved value and confirm its type."],"exampleFix":"# before\n[outputFormats.MYFORMAT]\nmediaType = [\"text/html\"]\n\n# after\n[outputFormats.MYFORMAT]\nmediaType = \"text/html\"","handlingStrategy":"type-guard","validationCode":"// mediaType must be a string scalar before decode.\nfunc ensureMediaTypeIsString(v any) error {\n    if _, ok := v.(string); !ok {\n        return fmt.Errorf(\"mediaType must be string, got %T\", v)\n    }\n    return nil\n}","typeGuard":"func isStringScalar(v any) bool {\n    _, ok := v.(string)\n    return ok\n}","tryCatchPattern":"if err := output.DecodeConfig(mediaTypes, in); err != nil {\n    // Distinguish type errors from missing media types in the message.\n    return fmt.Errorf(\"outputFormats decode: %w\", err)\n}","preventionTips":["Quote mediaType values: mediaType = \"text/html\".","Avoid list/scalar values for mediaType.","Lint config for type consistency."],"tags":["media-types","output-formats","type-mismatch","config","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}