{"record":{"id":"e1325f2462a3aaf1","repo":"yorukot/superfile","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/pkg/utils/file_utils.go","lineNumber":248,"sourceCode":"\t\t\t}\n\t\t}\n\t\treturn err\n\t})\n\tif walkErr != nil {\n\t\tslog.Error(\"errors during WalkDir\", \"error\", walkErr)\n\t}\n\treturn size\n}\n\n// Helper functions\n// Create all dirs that does not already exists\nfunc CreateDirectories(dirs ...string) error {\n\tfor _, dir := range dirs {\n\t\tif dir == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif err := os.MkdirAll(dir, ConfigDirPerm); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create directory %s: %w\", dir, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Create all files if they do not exists yet\nfunc CreateFiles(files ...string) error {\n\tfor _, file := range files {\n\t\tif _, err := os.Stat(file); os.IsNotExist(err) {\n\t\t\tif err = os.WriteFile(file, nil, ConfigFilePerm); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create file %s: %w\", file, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc ReadFileContent(filepath string, maxLineLength int, previewLine int) (string, error) {","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/pkg/utils/file_utils.go#L230-L266","documentation":"CreateDirectories runs os.MkdirAll with ConfigDirPerm for each provided path; this error wraps a failure to create one of them. MkdirAll creates the full hierarchy but still fails on permission, path, or filesystem problems. The function stops at the first directory that fails.","triggerScenarios":"InitConfigFile calling CreateDirectories with config/cache/data paths that cannot be created — parent dir not writable, a path component exists as a regular file, empty-ish path handled too late, or the filesystem is read-only.","commonSituations":"$HOME unset or pointing somewhere unwritable; XDG_CONFIG_HOME set to a read-only path; a file named like the config directory left behind by a bad install; sandboxed/container environments with read-only roots.","solutions":["Read the wrapped error to see which directory and why (EACCES vs EEXIST vs ENOTDIR).","Verify no regular file exists at the directory path (`ls -la <dir>`); remove/rename it if so.","Check parent permissions and ownership; mkdir -p manually as the runtime user to confirm.","Fix the environment (HOME/XDG_* vars) or pass explicit writable paths to CreateDirectories.","Prefer calling CreateDirectories before any file creation (InitConfigFile already does; keep that ordering in custom setup code)."],"exampleFix":"// before\nerr := utils.CreateDirectories(cfgDir) // cfgDir happens to be a file\n// after\nif info, err := os.Stat(cfgDir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", cfgDir)\n}\nif err := utils.CreateDirectories(cfgDir); err != nil { return err }","handlingStrategy":"validation","validationCode":"func ensureCreatableDir(dir string) error {\n    if dir == \"\" { return nil }\n    if info, err := os.Stat(dir); err == nil {\n        if !info.IsDir() { return fmt.Errorf(\"%s exists as a file\", dir) }\n        return nil\n    }\n    parent := filepath.Dir(dir)\n    if info, err := os.Stat(parent); err == nil && info.IsDir() {\n        f, e := os.CreateTemp(parent, \".t*\"); if e != nil { return e }; f.Close(); os.Remove(f.Name())\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := utils.CreateDirectories(dirs...); err != nil {\n    return fmt.Errorf(\"config dir setup failed: %w\", err)\n}","preventionTips":["Check HOME/XDG env vars resolve to writable locations before init.","Ensure no regular file collides with configured directory paths.","Run CreateDirectories before CreateFiles/InitJSONFile in all setup paths.","Test first-run behavior in a fresh container user's environment."],"tags":["filesystem","mkdir","permissions","config"],"backgroundTag":"mkdir-failed","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}