{"record":{"id":"7d9279adb198b1fa","repo":"xpzouying/xiaohongshu-mcp","slug":"failed-to-read-cookies-from-tmp-file","errorCode":null,"errorMessage":"failed to read cookies from tmp file","messagePattern":"failed to read cookies from tmp file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cookies/cookies.go","lineNumber":54,"sourceCode":"}\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 {\n\t\treturn f.Cookies, nil\n\t}\n\n\treturn data, nil\n}\n\n// LoadSeed 读取会话绑定的 seed。老格式（裸数组）没有这个值，返回 0。\nfunc (c *localCookie) LoadSeed() int {\n\tdata, err := os.ReadFile(c.path)\n\tif err != nil {\n\t\treturn 0\n\t}\n\n\tvar f sessionFile","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/cookies/cookies.go#L36-L72","documentation":"LoadCookies wraps an os.ReadFile failure on the cookie file path (cookies/cookies.go:54) via errors.Wrap. The most common wrapped cause is file-not-found (os.ErrNotExist), i.e. no session has been saved yet at the configured path. The path comes from NewLoadCookie(path) or GetCookiesFilePath(), which honors the COOKIES_PATH env var.","triggerScenarios":"Calling LoadCookies (directly or via SaveSeed, which calls LoadCookies first) when the cookie file doesn't exist at c.path, the path points to a directory, or the process lacks read permission.","commonSituations":"First run before any SaveCookies; COOKIES_PATH env var pointing to a stale/nonexistent location; running in a container where /tmp/cookies.json (legacy path) was wiped; permission mismatch after switching users.","solutions":["Check os.IsNotExist on the wrapped error — if so, perform a fresh login and SaveCookies to create the file.","Verify COOKIES_PATH / the path passed to NewLoadCookie points to the right file.","Check file permissions and that the path isn't a directory.","Treat a missing file as an empty session: re-authenticate rather than retrying the load."],"exampleFix":"// before\ncks, err := store.LoadCookies()\nif err != nil { return err }\n// after\ncks, err := store.LoadCookies()\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        return loginAndSaveSession(ctx) // first run\n    }\n    return err\n}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {\n    return loginAndSaveSession(ctx) // no session yet\n}","typeGuard":null,"tryCatchPattern":"cks, err := store.LoadCookies()\nif err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n        return freshLogin(ctx) // expected on first run\n    }\n    return err // real I/O problem (permissions, etc.)\n}","preventionTips":["Check file existence before loading on first run.","Pin COOKIES_PATH explicitly to avoid legacy /tmp path surprises.","Ensure consistent user/permissions across runs.","Treat missing file as 'needs login', not a fatal failure."],"tags":["filesystem","cookies","io","session"],"backgroundTag":"file-not-found","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"}