{"record":{"id":"b641d637c0b98769","repo":"JanDeDobbeleer/oh-my-posh","slug":"source-file-s-does-not-match-format-s","errorCode":null,"errorMessage":"source file %s does not match format %s","messagePattern":"source file (.+?) does not match format (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/dsc/config.go","lineNumber":78,"sourceCode":"\nfunc (s *ConfigResource) ToJSON() string {\n\toutput := s.Resource.ToJSON()\n\treturn config.EscapeGlyphs(output, false)\n}\n\nfunc (c *Configuration) Apply() error {\n\tif c == nil {\n\t\treturn nil\n\t}\n\n\tformats := map[string][]string{\n\t\tconfig.JSON: {\".json\", \".jsonc\"},\n\t\tconfig.YAML: {\".yaml\", \".yml\"},\n\t\tconfig.TOML: {\".toml\", \".tml\"},\n\t}\n\n\tif !slices.Contains(formats[c.Format], filepath.Ext(c.Source)) {\n\t\treturn fmt.Errorf(\"source file %s does not match format %s\", c.Source, c.Format)\n\t}\n\n\tlog.Debug(\"Applying configuration %s\", c.Source)\n\n\t// Expand tilde to home directory for file operations\n\tfilePath := strings.ReplaceAll(c.Source, \"~\", path.Home())\n\n\t// Create directory if it doesn't exist\n\tdir := filepath.Dir(filePath)\n\tif err := os.MkdirAll(dir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create directory %s: %w\", dir, err)\n\t}\n\n\tdata := c.Export(c.Format)\n\n\t// Write file\n\tif err := os.WriteFile(filePath, []byte(data), 0644); err != nil {\n\t\treturn fmt.Errorf(\"failed to write configuration file %s: %w\", filePath, err)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/dsc/config.go#L60-L96","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n{ \"format\": \"yaml\", \"source\": \"~/myconfig.omp.json\" }\n// after\n{ \"format\": \"json\", \"source\": \"~/myconfig.omp.json\" }","handlingStrategy":"validation","validationCode":"func validate(cfgFormat, source string) error {\n    ext := strings.ToLower(filepath.Ext(source))\n    valid := map[string][]string{\n        \"json\": {\".json\", \".jsonc\"},\n        \"yaml\": {\".yaml\", \".yml\"},\n        \"toml\": {\".toml\", \".tml\"},\n    }\n    if cfgFormat == \"\" { return fmt.Errorf(\"format is required\") }\n    if !slices.Contains(valid[cfgFormat], ext) {\n        return fmt.Errorf(\"format %s does not match extension %s of %s\", cfgFormat, ext, source)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Apply(); err != nil {\n    if strings.Contains(err.Error(), \"does not match format\") {\n        return fmt.Errorf(\"fix the DSC document: %w\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["validation","dsc","config","format-mismatch"],"backgroundTag":"format-mismatch","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}