{"id":"6d381f053ee15560","repo":"gohugoio/hugo","slug":"unsupported-format-q","errorCode":null,"errorMessage":"unsupported format: %q","messagePattern":"unsupported format: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/config.go","lineNumber":105,"sourceCode":"\tformat := strings.ToLower(c.format)\n\n\tswitch format {\n\tcase \"json\":\n\t\tos.Stdout.Write(buf.Bytes())\n\tdefault:\n\t\t// Decode the JSON to a map[string]interface{} and then unmarshal it again to the correct format.\n\t\tvar m map[string]any\n\t\tif err := json.Unmarshal(buf.Bytes(), &m); err != nil {\n\t\t\treturn err\n\t\t}\n\t\thmaps.ConvertFloat64WithNoDecimalsToInt(m)\n\t\tswitch format {\n\t\tcase \"yaml\":\n\t\t\treturn parser.InterfaceToConfig(m, metadecoders.YAML, os.Stdout)\n\t\tcase \"toml\":\n\t\t\treturn parser.InterfaceToConfig(m, metadecoders.TOML, os.Stdout)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported format: %q\", format)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (c *configCommand) Init(cd *simplecobra.Commandeer) error {\n\tc.r = cd.Root.Command.(*rootCommand)\n\tcmd := cd.CobraCommand\n\tcmd.Short = \"Display project configuration\"\n\tcmd.Long = `Display project configuration, both default and custom settings.`\n\tcmd.Flags().StringVar(&c.format, \"format\", \"toml\", \"preferred file format (toml, yaml or json)\")\n\t_ = cmd.RegisterFlagCompletionFunc(\"format\", cobra.FixedCompletions([]string{\"toml\", \"yaml\", \"json\"}, cobra.ShellCompDirectiveNoFileComp))\n\tcmd.Flags().StringVar(&c.lang, \"lang\", \"\", \"the language to display config for. Defaults to the first language defined.\")\n\tcmd.Flags().BoolVar(&c.printZero, \"printZero\", false, `include config options with zero values (e.g. false, 0, \"\") in the output`)\n\t_ = cmd.RegisterFlagCompletionFunc(\"lang\", cobra.NoFileCompletions)\n\tapplyLocalFlagsBuildConfig(cmd, c.r)\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/config.go#L87-L123","documentation":"Raised by `hugo config` when the (lowercased) value of `--format` is not one of json, yaml, or toml (commands/config.go:89-106). The command serializes the resolved site configuration to the requested format; anything outside those three encoders has no marshaller, so Hugo rejects it rather than guessing.","triggerScenarios":"Running `hugo config --format <x>` with any value other than toml, yaml, or json — e.g. `--format yml`, `--format xml`, `--format JSON5`, or an empty/typoed value passed via a script or alias.","commonSituations":"Using `yml` instead of `yaml` (a very common habit from other tools); CI scripts templating the flag from a variable that resolves to an unexpected value; expecting formats Hugo can read (JSON5, org, etc.) to also be supported as config-dump output.","solutions":["Use one of the three supported values exactly: `--format toml`, `--format yaml`, or `--format json` (case-insensitive).","Change `yml` to `yaml` — the short spelling is not accepted.","If the flag comes from a script variable, print/validate it before invoking hugo."],"exampleFix":"# before\nhugo config --format yml\n# after\nhugo config --format yaml","handlingStrategy":"validation","validationCode":"var supported = map[string]bool{\"json\": true, \"toml\": true, \"yaml\": true}\nif !supported[strings.ToLower(format)] {\n    return fmt.Errorf(\"format must be one of: json, toml, yaml\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"unsupported format\") {\n    // print the allowed format list and exit\n}","preventionTips":["Normalize (lowercase, trim) the format string before passing it","Validate against the documented set of supported formats at the CLI boundary","Default to a known-good format instead of passing through raw user input"],"tags":["hugo","cli","config","serialization"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}