{"record":{"id":"dda0cc5ac54d7eb8","repo":"xpzouying/xiaohongshu-mcp","slug":"path-is-required","errorCode":null,"errorMessage":"path is required","messagePattern":"path is required","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cookies/cookies.go","lineNumber":40,"sourceCode":"const localCookiesPath = \"cookies.json\"\n\ntype Cookier interface {\n\tLoadCookies() ([]byte, error)\n\tSaveCookies(data []byte) error\n\tDeleteCookies() error\n\t// LoadSeed 读取会话绑定的 seed；老格式、文件损坏或未设时返回 0。\n\tLoadSeed() int\n\t// SaveSeed 写入 seed，保留文件中已有的 cookies。\n\tSaveSeed(seed int) error\n}\n\ntype localCookie struct {\n\tpath string\n}\n\nfunc NewLoadCookie(path string) Cookier {\n\tif path == \"\" {\n\t\tpanic(\"path is required\")\n\t}\n\n\treturn &localCookie{\n\t\tpath: path,\n\t}\n}\n\n// LoadCookies 从文件中加载 cookies 数组的原始字节。\n// v2 从外层对象里取出 cookies 字段；v1 文件本身就是数组，原样返回。\nfunc (c *localCookie) LoadCookies() ([]byte, error) {\n\n\tdata, err := os.ReadFile(c.path)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to read cookies from tmp file\")\n\t}\n\n\tvar f sessionFile\n\tif err := json.Unmarshal(data, &f); err == nil && len(f.Cookies) > 0 {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/cookies/cookies.go#L22-L58","documentation":"NewLoadCookie panics with \"path is required\" when given an empty string. The cookie store requires an explicit file path; an empty path would silently point at a directory or fail later on read/write, so the constructor fails fast. It is a programming/config error, hence the panic rather than an error return.","triggerScenarios":"Calling cookies.NewLoadCookie(\"\") directly, or wiring a path variable that resolved to empty — e.g. os.Getenv(\"COOKIES_PATH\") returned \"\" and the caller passed it through without applying GetCookiesFilePath's fallback logic.","commonSituations":"Environment variable COOKIES_PATH set to empty in CI/Docker and used without a default; config struct field not populated before constructing the cookie loader; refactoring removed the GetCookiesFilePath() call and passed a raw env value.","solutions":["Use cookies.GetCookiesFilePath() to obtain a valid default path instead of a raw env lookup","Guard the path with a non-empty check before calling NewLoadCookie","Set COOKIES_PATH to a concrete file path in the deployment environment","Recover from this panic at startup, or switch to validating config before construction"],"exampleFix":"// before\nloader := cookies.NewLoadCookie(os.Getenv(\"COOKIES_PATH\")) // panics when env unset\n// after\npath := os.Getenv(\"COOKIES_PATH\")\nif path == \"\" {\n    path = cookies.GetCookiesFilePath()\n}\nloader := cookies.NewLoadCookie(path)","handlingStrategy":"validation","validationCode":"path := os.Getenv(\"COOKIES_PATH\")\nif path == \"\" {\n    path = cookies.GetCookiesFilePath() // applies fallbacks\n}\nif path == \"\" {\n    return errors.New(\"cookies path unresolved\")\n}","typeGuard":null,"tryCatchPattern":"func newCookieLoader(path string) (c cookies.Cookier, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"cookie loader: %v\", r) } }()\n    return cookies.NewLoadCookie(path), nil\n}","preventionTips":["Always source the path via cookies.GetCookiesFilePath(), never raw env reads","Validate non-empty config before constructing loaders","Set COOKIES_PATH explicitly in Docker/CI environments","Wrap constructors that panic in a recover at the config layer"],"tags":["panic","configuration","go","cookies"],"backgroundTag":"missing-env-var","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}