JanDeDobbeleer/oh-my-posh · error
invalid export format
Error message
invalid export format
What it means
The `oh-my-posh config export` command was invoked with a `--format` value the exporter does not recognize. The CLI switches on the format string and the `default:` branch rejects anything outside the supported set (json, jsonc, toml, tml, yaml, yml). The command prints the accepted list to stdout and exits with status code 2 before any export happens.
Source
Thrown at src/cli/config_export.go:67
setConfigFlag()
cfg := config.Load(configFlag)
validateExportFormat := func() error {
format = strings.ToLower(format)
switch format {
case config.JSON, config.JSONC:
format = config.JSON
case config.TOML, config.TML:
format = config.TOML
case config.YAML, config.YML:
format = config.YAML
default:
formats := []string{config.JSON, config.JSONC, config.TOML, config.TML, config.YAML, config.YML}
// usage error
fmt.Printf("export format must be one of these: %s\n", strings.Join(formats, ", "))
exitcode = 2
return errors.New("invalid export format")
}
return nil
}
if len(format) != 0 {
if err := validateExportFormat(); err != nil {
return
}
}
if output == "" {
fmt.Print(cfg.Export(format))
return
}
cfg.Source = cleanOutputPath(output)
View on GitHub (pinned to 0976794618)
Solutions
- Use one of the exact accepted values: json, jsonc, toml, tml, yaml, yml.
- Trim whitespace and match casing exactly as printed in the usage message (the error prints the full list).
- Check the spelling of the flag value — 'yam', 'jsn', etc. all land in the default branch.
- If scripting, validate the format value against the list before invoking the CLI so you get a clean failure.
Example fix
// before oh-my-posh config export --format json5 -o theme.json5 // after oh-my-posh config export --format jsonc -o theme.jsonc
Defensive patterns
Strategy: validation
Validate before calling
var validFormats = map[string]bool{"json": true, "jsonc": true, "toml": true, "tml": true, "yaml": true, "yml": true}
if !validFormats[strings.TrimSpace(format)] {
return fmt.Errorf("unsupported format %q; use json, jsonc, toml, tml, yaml, or yml", format)
} Try / catch
if err := exportConfig(format, out); err != nil {
if err.Error() == "invalid export format" {
fmt.Fprintln(os.Stderr, "usage: --format json|jsonc|toml|tml|yaml|yml")
os.Exit(2)
}
return err
} Prevention
- Keep a shared const/list of accepted format strings and validate CLI input against it in scripts
- Trim and normalize format values (lowercase, strip spaces) before passing to the CLI
- Check `oh-my-posh config export --help` after upgrades in case the accepted set changes
When it happens
Trigger: Running `oh-my-posh config export --format <value>` (or the equivalent `GetExport` flow) where format is not exactly one of config.JSON, JSONC, TOML, TML, YAML, YML — e.g. `--format yml ` with stray whitespace, `--format json5`, `--format YAML` if the comparison is case-sensitive, or a typo like `--format yam`.
Common situations: Users copying an example that uses an unsupported extension (`.ini`, `.json5`); scripting the flag from a config file extension that isn't mapped; passing uppercase or whitespace-padded values; confusing the export format with the config *read* format set.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- --data-only and --data-derive contradict each other: one for
- font path must be a valid URL
- no assets found
- we do not have permissions to update
- unclosed section:
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/263ece6cd5c8f296.
Report an issue: GitHub.