{"record":{"id":"c4de1c25ed02f67c","repo":"JanDeDobbeleer/oh-my-posh","slug":"failed-to-write-configuration-file-s-w","errorCode":null,"errorMessage":"failed to write configuration file %s: %w","messagePattern":"failed to write configuration file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/dsc/config.go","lineNumber":96,"sourceCode":"\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\n\treturn c.Source == other.Source\n}\n\nfunc (c *Configuration) Resolve() (*Configuration, bool) {\n\tlog.Debug(\"Resolving configuration %s\", c.Source)\n\n\tif c.resolved {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/dsc/config.go#L78-L114","documentation":"Configuration.Apply writes the exported config data with os.WriteFile; when that write fails, the error is wrapped with the target file path. The underlying syscall error (permission denied, disk full, target is a directory, read-only volume) is available via %w/errors.Unwrap or errors.As(*fs.PathError).","triggerScenarios":"Applying a DSC Configuration where the destination path exists as a directory, the user lacks write permission on the file or its directory, or the filesystem is read-only/full.","commonSituations":"Config file previously created by root so a normal user cannot overwrite it; Windows file locked by another process; overwriting a read-only file; destination path accidentally points at a directory name.","solutions":["Check the wrapped error and the path in the message: confirm the path is a file, not a directory, and that you have write permission","Fix ownership/permissions (chown/chmod) or delete the read-only/locked file so WriteFile can recreate it","Free disk space if the error indicates the volume is full","Run elevated only if the destination genuinely requires it; otherwise point Source at a user-writable location"],"exampleFix":"// before: file owned by root\n-rw-r--r-- root root ~/.config/oh-my-posh/config.omp.json\n// after\nsudo chown $USER ~/.config/oh-my-posh/config.omp.json","handlingStrategy":"validation","validationCode":"target := strings.ReplaceAll(source, \"~\", home)\nif st, err := os.Stat(target); err == nil && st.IsDir() {\n    return fmt.Errorf(\"%s is a directory, expected a file\", target)\n}\nif st, err := os.Stat(target); err == nil {\n    f, err := os.OpenFile(target, os.O_WRONLY, 0)\n    if err != nil { return fmt.Errorf(\"cannot write %s: %w\", target, err) }\n    f.Close()\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Apply(); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        switch {\n        case errors.Is(perr.Err, fs.ErrPermission):\n            return fmt.Errorf(\"fix permissions or ownership of %s\", perr.Path)\n        case errors.Is(perr.Err, syscall.ENOSPC):\n            return fmt.Errorf(\"disk full: free space and retry\")\n        }\n    }\n    return err\n}","preventionTips":["Ensure the config file is owned by the current user, not root","Do not set the read-only bit on theme/config files you expect dsc to rewrite","Keep enough free disk space; watch for ENOSPC in CI volumes","Confirm the Source path ends in a filename, not a directory"],"tags":["filesystem","permissions","dsc","io"],"backgroundTag":"file-write-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}