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

  1. Use one of: json, yaml, or toml
  2. Omit --format to use the default (toml)
  3. 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

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


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)