{"record":{"id":"37966db1c68e09c2","repo":"xpzouying/xiaohongshu-mcp","slug":"failed-to-unmarshal-feeds-w","errorCode":null,"errorMessage":"failed to unmarshal feeds: %w","messagePattern":"failed to unmarshal feeds: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/feeds.go","lineNumber":62,"sourceCode":"\t}\n\n\t// 轮询等 __INITIAL_STATE__.feed 注水就绪（替代固定 1s，治偶发 ErrNoFeeds）\n\tvar result string\n\tdeadline := time.Now().Add(8 * time.Second)\n\tfor {\n\t\tif result = readFeeds(); result != \"\" || time.Now().After(deadline) {\n\t\t\tbreak\n\t\t}\n\t\ttime.Sleep(300 * time.Millisecond)\n\t}\n\n\tif result == \"\" {\n\t\treturn nil, errors.ErrNoFeeds\n\t}\n\n\tvar feeds []Feed\n\tif err := json.Unmarshal([]byte(result), &feeds); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal feeds: %w\", err)\n\t}\n\n\treturn onlyNotes(feeds), nil\n}\n","sourceCodeStart":44,"sourceCodeEnd":67,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/feeds.go#L44-L67","documentation":"GetFeedsList 已从页面拿到 __INITIAL_STATE__.feed 的 JSON 字符串，但 json.Unmarshal 到 []Feed 失败：页面注水数据结构与 Feed 结构体定义不匹配（小红书前端改版）或数据被截断。","triggerScenarios":"The home/discover feed initial state changed shape (renamed fields, wrapped object instead of array) or the extraction returned an object/note-card HTML instead of a JSON array of feeds.","commonSituations":"xiaohongshu frontend update; extracting from a logged-out page where feeds list is absent and a different structure is returned; not-logged-in redirect rendering a different state.","solutions":["Log the raw result and diff against the []Feed json tags","Update the Feed struct tags to the current schema","Ensure you are on the expected page (logged in, correct tab) before extraction"],"exampleFix":"// before\nvar feeds []Feed\nif err := json.Unmarshal([]byte(result), &feeds); err != nil { return nil, ... }\n// after\nvar probe any\nif err := json.Unmarshal([]byte(result), &probe); err != nil { log.Printf(\"raw=%s\", result) } // inspect shape first","handlingStrategy":"type-guard","validationCode":"func looksLikeFeedArray(raw string) bool {\n    var probe []json.RawMessage\n    return json.Unmarshal([]byte(raw), &probe) == nil\n}","typeGuard":"func asFeedSlice(raw string) ([]json.RawMessage, bool) {\n    var s []json.RawMessage\n    if err := json.Unmarshal([]byte(raw), &s); err != nil { return nil, false }\n    return s, true\n}","tryCatchPattern":"feeds, err := client.GetFeedsList(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"unmarshal feeds\") {\n        log.Errorf(\"feeds schema drift: %v\", err)\n    }\n    return err\n}","preventionTips":["Verify you are logged in / on the expected feed page before listing","Log raw list payloads on failure to spot schema changes early","Keep the library updated with xiaohongshu frontend changes"],"tags":["json","unmarshal","schema-mismatch"],"backgroundTag":"json-unmarshal-error","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"}