JanDeDobbeleer/oh-my-posh · error
source file %s does not match format %s
Error message
source file %s does not match format %s
What it means
The dsc Configuration resource's Apply validates that the extension of Source matches the declared Format before writing the config file. If filepath.Ext(Source) is not in the extension list for c.Format (json/jsonc, yaml/yml, toml/tml), this error is returned. It is a pure declaration mismatch — no file I/O has happened yet.
Source
Thrown at src/cli/dsc/config.go:78
func (s *ConfigResource) ToJSON() string {
output := s.Resource.ToJSON()
return config.EscapeGlyphs(output, false)
}
func (c *Configuration) Apply() error {
if c == nil {
return nil
}
formats := map[string][]string{
config.JSON: {".json", ".jsonc"},
config.YAML: {".yaml", ".yml"},
config.TOML: {".toml", ".tml"},
}
if !slices.Contains(formats[c.Format], filepath.Ext(c.Source)) {
return fmt.Errorf("source file %s does not match format %s", c.Source, c.Format)
}
log.Debug("Applying configuration %s", c.Source)
// Expand tilde to home directory for file operations
filePath := strings.ReplaceAll(c.Source, "~", path.Home())
// Create directory if it doesn't exist
dir := filepath.Dir(filePath)
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("failed to create directory %s: %w", dir, err)
}
data := c.Export(c.Format)
// Write file
if err := os.WriteFile(filePath, []byte(data), 0644); err != nil {
return fmt.Errorf("failed to write configuration file %s: %w", filePath, err)View on GitHub (pinned to 0976794618)
Solutions
- Align the `format` field with the actual file extension (json for .json/.jsonc, yaml for .yaml/.yml, toml for .toml/.tml)
- Rename the source file so its extension matches the declared format
- Remove the format field if the source is loaded first — Resolve() sets Format from the loaded config, so let resolution fill it in
- Check the format string for typos and confirm it is one of json, jsonc, yaml, yml, toml, tml
Example fix
// before
{ "format": "yaml", "source": "~/myconfig.omp.json" }
// after
{ "format": "json", "source": "~/myconfig.omp.json" } Defensive patterns
Strategy: validation
Validate before calling
func validate(cfgFormat, source string) error {
ext := strings.ToLower(filepath.Ext(source))
valid := map[string][]string{
"json": {".json", ".jsonc"},
"yaml": {".yaml", ".yml"},
"toml": {".toml", ".tml"},
}
if cfgFormat == "" { return fmt.Errorf("format is required") }
if !slices.Contains(valid[cfgFormat], ext) {
return fmt.Errorf("format %s does not match extension %s of %s", cfgFormat, ext, source)
}
return nil
} Try / catch
if err := cfg.Apply(); err != nil {
if strings.Contains(err.Error(), "does not match format") {
return fmt.Errorf("fix the DSC document: %w", err)
}
return err
} Prevention
- Let Resolve() derive Format from the loaded config instead of hardcoding it in the DSC document
- Keep file extensions lowercase and canonical (.omp.json, .omp.yaml, .omp.toml)
- Cross-check format/source pairs in your DSC document before applying
- Never leave the format field set from a copied template entry
When it happens
Trigger: Applying a DSC Configuration whose `format` field does not match the `source` file extension, e.g. format "yaml" with a .json source, an empty or misspelled format string, or a source with no extension.
Common situations: Hand-written DSC documents where format was copied from another entry; a file named config.txt or with an uppercase extension variant not in the list; Format left empty so formats[c.Format] is nil and the contains check fails; a format value like "json5" or "yml" typoed into an unsupported key.
Related errors
- no location configured: set city+country or latitude+longitu
- unsupported shell type: %s
- invalid export format
- --data-only and --data-derive contradict each other: one for
- font path must be a valid URL
AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31).
Data as JSON: /api/errors/b641d637c0b98769.
Report an issue: GitHub.