{"record":{"id":"67966d7cf7dc0378","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-create-directory-s-w","errorCode":null,"errorMessage":"failed to create directory %s: %w","messagePattern":"failed to create directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/dsc/config.go","lineNumber":89,"sourceCode":"\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)\n\t}\n\n\tlog.Debug(\"Configuration written to %s\", filePath)\n\treturn nil\n}\n\nfunc (c *Configuration) Equal(other *Configuration) bool {\n\tif other == nil {\n\t\treturn false\n\t}\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/dsc/config.go#L71-L107","documentation":"Configuration.Apply ensures the destination directory of the source path exists via os.MkdirAll before writing. When the OS refuses to create that directory (permission denied, read-only filesystem, path is an existing file, invalid path characters), the error is wrapped with the directory path. The wrapped %w contains the underlying syscall error.","triggerScenarios":"Applying a DSC Configuration whose target directory cannot be created: parent dir owned by root, target path component is an existing regular file, disk full, or a path with illegal characters on Windows.","commonSituations":"Storing the config in a system directory like /etc or C:\\Windows without elevation; HOME pointing somewhere unwritable; a stale file occupying the directory name; network/removable drive not mounted.","solutions":["Read the wrapped %w error to see the exact OS reason (permission denied, not a directory, etc.)","Create or fix permissions on the directory manually (mkdir -p, chmod/chown) or run with the privileges required","Ensure no regular file exists at the directory path; rename or remove it","Check that the drive/volume holding the path is mounted and writable, and that HOME resolves correctly"],"exampleFix":"// before: applying to /etc/oh-my-posh/config.omp.json as a non-root user\n// after\nsudo oh-my-posh dsc apply   # or target a writable path like ~/.config/oh-my-posh/","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(strings.ReplaceAll(source, \"~\", os.UserHomeDir()))\nif st, err := os.Stat(dir); err == nil && !st.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", dir)\n}\nif err := os.MkdirAll(dir, 0o755); err != nil {\n    return fmt.Errorf(\"pre-check: cannot create %s: %w\", dir, err)\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Apply(); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, fs.ErrPermission) {\n        return fmt.Errorf(\"need write access to %s: %w\", perr.Path, err)\n    }\n    return err\n}","preventionTips":["Point config sources at user-writable locations like ~/.config/oh-my-posh/","Check that no regular file occupies the target directory path","Avoid system directories (/etc, C:\\Windows) unless running elevated","Ensure the volume holding the path is mounted and writable"],"tags":["filesystem","permissions","dsc","io"],"backgroundTag":"mkdir-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}