{"record":{"id":"6c2ee0f9788373b9","repo":"bcicen/ctop","slug":"failed-to-create-config-dir-s-s","errorCode":null,"errorMessage":"failed to create config dir [%s]: %s","messagePattern":"failed to create config dir \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/file.go","lineNumber":90,"sourceCode":"\t\t}\n\t\tSetColumns(colNames)\n\t}\n\n\treturn nil\n}\n\nfunc Write() (path string, err error) {\n\tpath, err = getConfigPath()\n\tif err != nil {\n\t\treturn path, err\n\t}\n\n\tcfgdir := filepath.Dir(path)\n\t// create config dir if not exist\n\tif _, err := os.Stat(cfgdir); err != nil {\n\t\terr = os.MkdirAll(cfgdir, 0755)\n\t\tif err != nil {\n\t\t\treturn path, fmt.Errorf(\"failed to create config dir [%s]: %s\", cfgdir, err)\n\t\t}\n\t}\n\n\t// remove prior to writing new file\n\tif err := os.Remove(path); err != nil {\n\t\tif !os.IsNotExist(err) {\n\t\t\treturn path, err\n\t\t}\n\t}\n\n\tfile, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)\n\tif err != nil {\n\t\treturn path, fmt.Errorf(\"failed to open config for writing: %s\", err)\n\t}\n\n\twriter := toml.NewEncoder(file)\n\terr = writer.Encode(exportConfig())\n\tif err != nil {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/bcicen/ctop/blob/59f00dd6aaebf48f3bc501e174f75f815c2619f0/config/file.go#L72-L108","documentation":"During config.Write, the target directory is created with os.MkdirAll if it does not exist. If that mkdir fails (permissions, read-only filesystem, path is a file), Write wraps the error with the directory path and underlying cause.","triggerScenarios":"os.MkdirAll(cfgdir, 0755) returns an error — e.g. parent directory not writable, disk full, or a file exists at the config directory path.","commonSituations":"$HOME or XDG_CONFIG_HOME pointing to a non-writable or nonexistent location; running in a sandboxed/containerized environment with read-only home; permission changes after setup.","solutions":["Check/fix permissions on the config directory's parent (chmod/u chown)","Verify $HOME and XDG_CONFIG_HOME point to writable directories","Ensure no regular file occupies the config directory path","Check disk space and mount flags (read-only fs)"],"exampleFix":"// before\nHOME=/ro-mount  # read-only\n// after\nexport XDG_CONFIG_HOME=/tmp/app-config  # writable location","handlingStrategy":"try-catch","validationCode":"cfgdir := filepath.Dir(path)\nif st, err := os.Stat(cfgdir); err != nil || !st.IsDir() {\n    if fi, err2 := os.Stat(filepath.Dir(cfgdir)); err2 != nil || !fi.IsDir() || !writable(fi) { /* fix env */ }\n}","typeGuard":null,"tryCatchPattern":"_, err := config.Write()\nif err != nil && strings.HasPrefix(err.Error(), \"failed to create config dir\") {\n    // fall back to a writable temp config dir\n}","preventionTips":["Ensure HOME/XDG_CONFIG_HOME point to writable directories","Check disk space and mount flags","Avoid placing a file where the config dir should be"],"tags":["filesystem","permissions","config"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"59f00dd6aaebf48f3bc501e174f75f815c2619f0","analyzedAt":"2026-09-02T23:34:03.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}