gohugoio/hugo · error
unsupported format
Error message
unsupported format: %q
What it means
The hugo config --format command supports only json, yaml, and toml (config.go:99-106). The default format is toml. Any other format value falls through to the default case and returns this error.
Solutions
- Use one of: json, yaml, or toml
- Omit --format to use the default (toml)
- Check the spelling of the format value
Example fix
# before hugo config --format xml # after hugo config --format yaml
Defensive patterns
Strategy: validation
Validate before calling
// Validate the --format value.
var validConfigFormats = map[string]bool{"json": true, "yaml": true, "toml": true}
func validateConfigFormat(format string) error {
if !validConfigFormats[strings.ToLower(format)] {
return fmt.Errorf("unsupported format: %q", format)
}
return nil
} Prevention
- Use only json, yaml, or toml for --format
- Omit --format to use the default (toml)
- Enable shell completion for the format flag
When it happens
Trigger: Running hugo config --format xml, --format ini, --format env, or any unsupported format string.
Common situations: Typo in the format name; assuming other serialization formats are supported; copy-paste errors.
Related errors
- invalid log level: , must be one of debug, warn, info or…
- language not found
- --appendPort=false not supported when in multihost mode
- config needs a filename
- failed to create workingDir
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/6d381f053ee15560.
Report an issue: GitHub.
Appendix: source
Thrown at commands/config.go:105
format := strings.ToLower(c.format)
switch format {
case "json":
os.Stdout.Write(buf.Bytes())
default:
// Decode the JSON to a map[string]interface{} and then unmarshal it again to the correct format.
var m map[string]any
if err := json.Unmarshal(buf.Bytes(), &m); err != nil {
return err
}
hmaps.ConvertFloat64WithNoDecimalsToInt(m)
switch format {
case "yaml":
return parser.InterfaceToConfig(m, metadecoders.YAML, os.Stdout)
case "toml":
return parser.InterfaceToConfig(m, metadecoders.TOML, os.Stdout)
default:
return fmt.Errorf("unsupported format: %q", format)
}
}
return nil
}
func (c *configCommand) Init(cd *simplecobra.Commandeer) error {
c.r = cd.Root.Command.(*rootCommand)
cmd := cd.CobraCommand
cmd.Short = "Display project configuration"
cmd.Long = `Display project configuration, both default and custom settings.`
cmd.Flags().StringVar(&c.format, "format", "toml", "preferred file format (toml, yaml or json)")
_ = cmd.RegisterFlagCompletionFunc("format", cobra.FixedCompletions([]string{"toml", "yaml", "json"}, cobra.ShellCompDirectiveNoFileComp))
cmd.Flags().StringVar(&c.lang, "lang", "", "the language to display config for. Defaults to the first language defined.")
cmd.Flags().BoolVar(&c.printZero, "printZero", false, `include config options with zero values (e.g. false, 0, "") in the output`)
_ = cmd.RegisterFlagCompletionFunc("lang", cobra.NoFileCompletions)
applyLocalFlagsBuildConfig(cmd, c.r)
View on GitHub (pinned to 52c9bd7908)