{"record":{"id":"730a63f5c0b99a2d","repo":"fish2018/pansou","slug":"v-730a63","errorCode":null,"errorMessage":"创建存储目录失败: %v","messagePattern":"创建存储目录失败: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/weibo/weibo.go","lineNumber":459,"sourceCode":"\n\tplugin.RegisterGlobalPlugin(p)\n}\n\n// Initialize 实现 InitializablePlugin 接口，延迟初始化插件\nfunc (p *WeiboPlugin) Initialize() error {\n\tif p.initialized {\n\t\treturn nil\n\t}\n\n\t// 初始化存储目录路径\n\tcachePath := os.Getenv(\"CACHE_PATH\")\n\tif cachePath == \"\" {\n\t\tcachePath = \"./cache\"\n\t}\n\tStorageDir = filepath.Join(cachePath, \"weibo_users\")\n\n\tif err := os.MkdirAll(StorageDir, 0755); err != nil {\n\t\treturn fmt.Errorf(\"创建存储目录失败: %v\", err)\n\t}\n\n\tp.loadAllUsers()\n\tgo p.startCleanupTask()\n\n\tp.initialized = true\n\treturn nil\n}\n\nfunc (p *WeiboPlugin) RegisterWebRoutes(router *gin.RouterGroup) {\n\tweibo := router.Group(\"/weibo\")\n\tweibo.GET(\"/:param\", p.handleManagePage)\n\tweibo.POST(\"/:param\", p.handleManagePagePOST)\n\t\n\tfmt.Printf(\"[Weibo] Web路由已注册: /weibo/:param\\n\")\n}\n\nfunc (p *WeiboPlugin) SkipServiceFilter() bool {","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/weibo/weibo.go#L441-L477","documentation":"During weibo plugin Initialize, the storage directory for cached weibo user data (cachePath/weibo_users) is created with os.MkdirAll. If directory creation fails (permission denied, read-only filesystem, path is a file), Initialize returns '创建存储目录失败' (failed to create storage directory) and the plugin fails to start.","triggerScenarios":"Calling Initialize when cachePath resolves to a location the process cannot write (e.g. /cache root-owned in a container), the path exists as a regular file, or the disk is read-only/full.","commonSituations":"Docker container running as non-root with default ./cache under a root-owned volume; cachePath env/config pointing at a system path without permissions; a file named 'cache' blocking directory creation; read-only root filesystem with no writable volume mounted.","solutions":["Set the cachePath config/env to a writable directory (e.g. /tmp or a mounted volume)","Ensure the process user owns or can write the cachePath parent","Remove any regular file that occupies the cachePath","Mount a writable volume in containers and point StorageDir there","Check disk space / read-only mount status"],"exampleFix":"// before\nif err := os.MkdirAll(StorageDir, 0755); err != nil {\n    return fmt.Errorf(\"创建存储目录失败: %v\", err)\n}\n// after\nif err := os.MkdirAll(StorageDir, 0755); err != nil {\n    return fmt.Errorf(\"创建存储目录失败 %s: %w\", StorageDir, err)\n}\n// deploy side: docker run -v weibo_cache:/data/cache -e CACHE_PATH=/data/cache ...","handlingStrategy":"try-catch","validationCode":"cacheDir := filepath.Join(cachePath, \"weibo_users\")\nif err := os.MkdirAll(cacheDir, 0755); err != nil {\n    return fmt.Errorf(\"cache dir not writable %s: %w\", cacheDir, err)\n}\n// run this probe (or a writable-file test) before Initialize","typeGuard":null,"tryCatchPattern":"if err := weiboPlugin.Initialize(cfg); err != nil {\n    if strings.Contains(err.Error(), \"创建存储目录失败\") {\n        cfg[\"cachePath\"] = os.TempDir() // retry with a writable dir\n        err = weiboPlugin.Initialize(cfg)\n    }\n    if err != nil { return err }\n}","preventionTips":["Run the process as a user with write access to cachePath","Point cachePath at a mounted writable volume in containers","Verify cachePath is not occupied by a regular file","Check disk space and mount flags (ro) at deploy time"],"tags":["filesystem","permissions","initialization","directory"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}