{"id":"a2fb42c28cc3d600","repo":"gohugoio/hugo","slug":"failed-to-decode-output-format-configuration-w","errorCode":null,"errorMessage":"failed to decode output format configuration: %w","messagePattern":"failed to decode output format configuration: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/config.go","lineNumber":139,"sourceCode":"\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\n}\n","sourceCodeStart":121,"sourceCodeEnd":144,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/output/config.go#L121-L144","documentation":"A wrapper error from output/config.go:139 emitted when mapstructure fails to decode the [outputFormats] configuration block into Hugo's output format struct. It wraps the underlying decode error (%w), which may itself be error 477/478 from the media-type hook or a generic type-mismatch from mapstructure. It means the overall shape of an output format entry doesn't fit the expected schema (name, mediaType, baseName, isPlainText, permalinkable, etc.).","triggerScenarios":"Any decoder.Decode failure over outputFormats input: wrong-typed fields (e.g. isPlainText as a string that can't weakly coerce, weight as a non-number), unknown structural shapes, or hook errors like an unresolvable media type propagating up.","commonSituations":"Malformed [outputFormats] blocks after hand-editing TOML/YAML; indentation mistakes in YAML turning scalar fields into maps; copying config across Hugo versions with changed field names; the wrapped media-type errors above.","solutions":["Read the wrapped cause after the colon — it names the exact field or media type that failed.","Compare your [outputFormats] entry against the documented schema (mediaType string, baseName string, isPlainText/permalinkable bool, weight int) and fix the mismatched field.","Validate config syntax (hugo config) and fix YAML/TOML structure errors.","If the cause is a media type, apply the fixes for 'media type not found' (declare it under [mediaTypes])."],"exampleFix":"# before\n[outputFormats.SearchIndex]\nisPlainText = \"yes-please\"\n\n# after\n[outputFormats.SearchIndex]\nisPlainText = true\nmediaType = \"application/json\"","handlingStrategy":"try-catch","validationCode":"// Keep outputFormats entries to known keys with correct types:\n// name (implicit), mediaType (string), baseName, path, rel (strings),\n// isPlainText, isHTML, noUgly, notAlternative, permalinkable, weight (bool/int)","typeGuard":null,"tryCatchPattern":"if err := loadConfig(); err != nil && strings.Contains(err.Error(), \"failed to decode output format configuration\") {\n    // unwrap with errors.Unwrap / %+v to see the mapstructure field that failed, fix that key's type\n}","preventionTips":["Match key names and value types exactly to the documented output format fields (booleans as booleans, weight as int)","Copy a documented outputFormats example as a starting point rather than hand-writing keys","Validate config changes in CI with a build before merging"],"tags":["hugo","configuration","output-formats","decode"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}