{"record":{"id":"16c0131fc0d8ce3f","repo":"fish2018/pansou","slug":"w-16c013","errorCode":null,"errorMessage":"加载配置失败: %w","messagePattern":"加载配置失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/panlian/panlian.go","lineNumber":535,"sourceCode":"\treturn Description\n}\n\nfunc (p *PanlianPlugin) Initialize() error {\n\tif p.initialized {\n\t\treturn nil\n\t}\n\n\tcachePath := os.Getenv(\"CACHE_PATH\")\n\tif cachePath == \"\" {\n\t\tcachePath = \"./cache\"\n\t}\n\tstorageDir = filepath.Join(cachePath, \"panlian_users\")\n\n\tif err := os.MkdirAll(storageDir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"创建存储目录失败: %w\", err)\n\t}\n\tif err := p.loadConfig(); err != nil {\n\t\treturn fmt.Errorf(\"加载配置失败: %w\", err)\n\t}\n\tp.loadAllUsers()\n\tp.initialized = true\n\treturn nil\n}\n\nfunc (p *PanlianPlugin) RegisterWebRoutes(router *gin.RouterGroup) {\n\tgroup := router.Group(\"/panlian\")\n\tgroup.GET(\"/:param\", p.handleManagePage)\n\tgroup.POST(\"/:param\", p.handleManagePagePOST)\n}\n\nfunc (p *PanlianPlugin) Search(keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {\n\tresult, err := p.SearchWithResult(keyword, ext)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn result.Results, nil","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/panlian/panlian.go#L517-L553","documentation":"PanlianPlugin.Initialize calls p.loadConfig() after creating the storage directory; a failure is wrapped as '加载配置失败' ('failed to load config'). It means the plugin's persisted configuration (file in the storage dir) could not be read or parsed, so initialization is aborted.","triggerScenarios":"loadConfig fails when the config file under storageDir (panlian_users dir) is missing/corrupt/unreadable, or contains invalid JSON, typically right after a failed mkdir or a partially-written config from a previous crash.","commonSituations":"Config file truncated by an unclean shutdown; permissions changed on the cache dir; config JSON hand-edited with a syntax error; storage dir wiped but expected fields absent and loader requires them.","solutions":["Inspect and fix or delete the corrupt config file in <cachePath>/panlian_users so the plugin can regenerate defaults.","Check file permissions on the storage dir and config file.","Validate the config JSON syntax (jq . <configfile>).","Re-initialize the plugin with a fresh cache directory after backing up user data."],"exampleFix":"// before\n$ cat cache/panlian_users/config.json  // trailing comma -> parse error\n// after\n$ mv cache/panlian_users/config.json config.json.bak\n$ # restart; plugin recreates default config","handlingStrategy":"fallback","validationCode":"// before Initialize, sanity-check the persisted config\nif data, err := os.ReadFile(cfgPath); err == nil {\n    var v map[string]any\n    if err := json.Unmarshal(data, &v); err != nil {\n        os.Rename(cfgPath, cfgPath+\".corrupt\") // let plugin regenerate\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := plugin.Initialize(cachePath, cfg); err != nil {\n    if strings.Contains(err.Error(), \"加载配置失败\") {\n        resetPluginConfig() // delete/regenerate config then retry once\n        return plugin.Initialize(cachePath, cfg)\n    }\n    return err\n}","preventionTips":["Write config atomically (temp file + rename) so crashes never leave truncated JSON.","Validate config JSON after any manual edit.","Back up panlian_users before wiping the cache dir.","Keep plugin and config schema versions in sync."],"tags":["config","initialization","file-read","plugin"],"backgroundTag":"config-file-not-found","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"}