{"record":{"id":"e8b54a7f3d18319a","repo":"charmbracelet/glow","slug":"unable-to-create-config-file-w","errorCode":null,"errorMessage":"unable to create config file: %w","messagePattern":"unable to create config file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config_cmd.go","lineNumber":77,"sourceCode":"\t\tif err := os.MkdirAll(filepath.Dir(configFile), 0o755); err != nil { //nolint:gosec\n\t\t\treturn fmt.Errorf(\"could not write configuration file: %w\", err)\n\t\t}\n\t}\n\n\tif ext := path.Ext(configFile); ext != \".yaml\" && ext != \".yml\" {\n\t\treturn fmt.Errorf(\"'%s' is not a supported configuration type: use '%s' or '%s'\", ext, \".yaml\", \".yml\")\n\t}\n\n\tif _, err := os.Stat(configFile); errors.Is(err, fs.ErrNotExist) {\n\t\t// File doesn't exist yet, create all necessary directories and\n\t\t// write the default config file\n\t\tif err := os.MkdirAll(filepath.Dir(configFile), 0o700); err != nil {\n\t\t\treturn fmt.Errorf(\"unable create directory: %w\", err)\n\t\t}\n\n\t\tf, err := os.Create(configFile)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to create config file: %w\", err)\n\t\t}\n\t\tdefer func() { _ = f.Close() }()\n\n\t\tif _, err := f.WriteString(defaultConfig); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to write config file: %w\", err)\n\t\t}\n\t} else if err != nil { // some other error occurred\n\t\treturn fmt.Errorf(\"unable to stat config file: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":59,"sourceCodeEnd":89,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/config_cmd.go#L59-L89","documentation":"Still in the config-does-not-exist branch of ensureConfigFile: after the directory is made, os.Create(configFile) opens (and creates) the file for writing the default configuration. This error wraps os.Create failing. The directory was just verified, so failures here are about the file path itself.","triggerScenarios":"The target path already exists as a directory (os.Create on a directory fails); permission denied on the just-created directory because umask/ACLs block write; filename too long; the filesystem rejects creation (read-only mount, immutable attr); symlink loop at the path.","commonSituations":"A directory accidentally named glow.yml where the config file should go; strict umask 0777 environments; NFS or network mounts with root-squash when running as root; antivirus/FIM tools blocking file creation.","solutions":["Check what is at the path: ls -ld <configFile> — if it is a directory, rename or remove it","Confirm write permission on the parent: touch <configFile> manually to reproduce","Choose a different location via --config","On NFS/root-squash setups, run as the owning user or use a local path"],"exampleFix":"# before\n$ glow config --config ~/cfg/glow.yml\n# Error: unable to create config file: open ~/cfg/glow.yml: is a directory\n\n# after\n$ rmdir ~/cfg/glow.yml && glow config --config ~/cfg/glow.yml","handlingStrategy":"validation","validationCode":"func canCreateFile(p string) error {\n\tif fi, err := os.Stat(p); err == nil && fi.IsDir() {\n\t\treturn fmt.Errorf(\"%s is a directory; a config file is expected\", p)\n\t}\n\tf, err := os.OpenFile(p, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot create %s: %w\", p, err)\n\t}\n\treturn f.Close() // leave creation to glow\n}","typeGuard":null,"tryCatchPattern":"if err := ensureConfigFile(); err != nil {\n\tif strings.Contains(err.Error(), \"unable to create config file\") && errors.Is(err, os.ErrPermission) {\n\t\t// switch to a writable location rather than fighting the mount\n\t\tconfigFile = filepath.Join(os.TempDir(), \"glow.yml\")\n\t\treturn ensureConfigFile()\n\t}\n\treturn err\n}","preventionTips":["Check the exact --config path is not already a directory (rmdir it if so)","On NFS/root-squash or mounted volumes, run glow as the owning user","Pre-create the empty file yourself (touch) when a security agent interferes with app-created files"],"tags":["config","filesystem","file-creation","permissions"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}