fish2018/pansou · error
创建存储目录失败
Error message
创建存储目录失败: %v
What it means
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.
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
Example fix
// before
if err := os.MkdirAll(StorageDir, 0755); err != nil {
return fmt.Errorf("创建存储目录失败: %v", err)
}
// after
if err := os.MkdirAll(StorageDir, 0755); err != nil {
return fmt.Errorf("创建存储目录失败 %s: %w", StorageDir, err)
}
// deploy side: docker run -v weibo_cache:/data/cache -e CACHE_PATH=/data/cache ... Defensive patterns
Strategy: try-catch
Validate before calling
cacheDir := filepath.Join(cachePath, "weibo_users")
if err := os.MkdirAll(cacheDir, 0755); err != nil {
return fmt.Errorf("cache dir not writable %s: %w", cacheDir, err)
}
// run this probe (or a writable-file test) before Initialize Try / catch
if err := weiboPlugin.Initialize(cfg); err != nil {
if strings.Contains(err.Error(), "创建存储目录失败") {
cfg["cachePath"] = os.TempDir() // retry with a writable dir
err = weiboPlugin.Initialize(cfg)
}
if err != nil { return err }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/730a63f5c0b99a2d.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/weibo/weibo.go:459
plugin.RegisterGlobalPlugin(p)
}
// Initialize 实现 InitializablePlugin 接口,延迟初始化插件
func (p *WeiboPlugin) Initialize() error {
if p.initialized {
return nil
}
// 初始化存储目录路径
cachePath := os.Getenv("CACHE_PATH")
if cachePath == "" {
cachePath = "./cache"
}
StorageDir = filepath.Join(cachePath, "weibo_users")
if err := os.MkdirAll(StorageDir, 0755); err != nil {
return fmt.Errorf("创建存储目录失败: %v", err)
}
p.loadAllUsers()
go p.startCleanupTask()
p.initialized = true
return nil
}
func (p *WeiboPlugin) RegisterWebRoutes(router *gin.RouterGroup) {
weibo := router.Group("/weibo")
weibo.GET("/:param", p.handleManagePage)
weibo.POST("/:param", p.handleManagePagePOST)
fmt.Printf("[Weibo] Web路由已注册: /weibo/:param\n")
}
func (p *WeiboPlugin) SkipServiceFilter() bool {View on GitHub (pinned to beaa561337)