{"record":{"id":"7afac2b9f3e07b1c","repo":"apache/answer","slug":"create-directory-fail-s","errorCode":null,"errorMessage":"create directory fail %s","messagePattern":"create directory fail (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/install.go","lineNumber":56,"sourceCode":"\tInstallI18nBundle(false)\n\tfmt.Println(\"install all initial environment done\")\n}\n\nfunc InstallConfigFile(configFilePath string) error {\n\tif len(configFilePath) == 0 {\n\t\tconfigFilePath = filepath.Join(path.ConfigFileDir, path.DefaultConfigFileName)\n\t}\n\tfmt.Println(\"[config-file] try to create at \", configFilePath)\n\n\t// if config file already exists do nothing.\n\tif CheckConfigFile(configFilePath) {\n\t\tfmt.Printf(\"[config-file] %s already exists\\n\", configFilePath)\n\t\treturn nil\n\t}\n\n\tif err := dir.CreateDirIfNotExist(path.ConfigFileDir); err != nil {\n\t\tfmt.Printf(\"[config-file] create directory fail %s\\n\", err.Error())\n\t\treturn fmt.Errorf(\"create directory fail %s\", err.Error())\n\t}\n\tfmt.Printf(\"[config-file] create directory success, config file is %s\\n\", configFilePath)\n\n\tif err := writer.WriteFile(configFilePath, string(configs.Config)); err != nil {\n\t\tfmt.Printf(\"[config-file] install fail %s\\n\", err.Error())\n\t\treturn fmt.Errorf(\"write file failed %s\", err)\n\t}\n\tfmt.Printf(\"[config-file] install success\\n\")\n\treturn nil\n}\n\nfunc installUploadDir() {\n\tfmt.Println(\"[upload-dir] try to install...\")\n\tif err := dir.CreateDirIfNotExist(path.UploadFilePath); err != nil {\n\t\tfmt.Printf(\"[upload-dir] install fail %s\\n\", err.Error())\n\t} else {\n\t\tfmt.Printf(\"[upload-dir] install success, upload directory is %s\\n\", path.UploadFilePath)\n\t}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/install.go#L38-L74","documentation":"InstallConfigFile returns this when dir.CreateDirIfNotExist(path.ConfigFileDir) fails while installing the default config file. The library cannot create the directory that will hold the config file, so installation aborts.","triggerScenarios":"InitEnvironment -> InstallConfigFile runs and the OS refuses to create path.ConfigFileDir (permission denied, path is a file, read-only filesystem).","commonSituations":"Running CLI as a user without write access to the data directory, dataDirPath pointing at an existing regular file, container volume mounted read-only.","solutions":["Check and fix filesystem permissions on the parent of path.ConfigFileDir.","Ensure the configured data dir path is a directory, not an existing file.","Run with sufficient privileges or point the data dir to a writable location."],"exampleFix":"// before\nif err := dir.CreateDirIfNotExist(path.ConfigFileDir); err != nil {\n    return fmt.Errorf(\"create directory fail %s\", err.Error())\n}\n// after (pre-check by caller)\nif _, statErr := os.Stat(dataDirPath); os.IsNotExist(statErr) {\n    os.MkdirAll(dataDirPath, 0o755)\n}\nif err := dir.CreateDirIfNotExist(path.ConfigFileDir); err != nil {\n    return fmt.Errorf(\"create directory fail %s\", err.Error())\n}","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(dataDirPath); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s is not a directory\", dataDirPath)\n}\nif err := os.MkdirAll(path.ConfigFileDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot create config dir: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run CLI with a user owning the data dir","Mount volumes read-write in containers","Pre-create data directories with correct permissions"],"tags":["filesystem","permissions","cli"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}