{"record":{"id":"501e521f35b1f067","repo":"fish2018/pansou","slug":"w-501e52","errorCode":null,"errorMessage":"解析搜索数据失败: %w","messagePattern":"解析搜索数据失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/gying/gying.go","lineNumber":2523,"sourceCode":"\t\t}\n\t\treturn nil, fmt.Errorf(\"未找到搜索结果数据\")\n\t}\n\n\tif DebugLog {\n\t\tjsonStr := string(matches[1])\n\t\tif len(jsonStr) > 200 {\n\t\t\tjsonStr = jsonStr[:200] + \"...\"\n\t\t}\n\t\tfmt.Printf(\"[Gying] 提取的JSON数据: %s\\n\", jsonStr)\n\t}\n\n\tvar searchData SearchData\n\tif err := json.Unmarshal(matches[1], &searchData); err != nil {\n\t\tif DebugLog {\n\t\t\tfmt.Printf(\"[Gying] JSON解析失败: %v\\n\", err)\n\t\t\tfmt.Printf(\"[Gying] 原始JSON: %s\\n\", string(matches[1]))\n\t\t}\n\t\treturn nil, fmt.Errorf(\"解析搜索数据失败: %w\", err)\n\t}\n\n\tif DebugLog {\n\t\tfmt.Printf(\"[Gying] 搜索数据解析成功:\\n\")\n\t\tfmt.Printf(\"[Gying]   - 关键词: %s\\n\", searchData.Q)\n\t\tfmt.Printf(\"[Gying]   - 结果数量字符串: %s\\n\", searchData.N)\n\t\tfmt.Printf(\"[Gying]   - 资源ID数组长度: %d\\n\", len(searchData.L.I))\n\t\tfmt.Printf(\"[Gying]   - 标题数组长度: %d\\n\", len(searchData.L.Title))\n\t\tif len(searchData.L.I) > 0 {\n\t\t\tfmt.Printf(\"[Gying]   - 前3个资源ID: %v\\n\", searchData.L.I[:min(3, len(searchData.L.I))])\n\t\t\tfmt.Printf(\"[Gying]   - 前3个标题: %v\\n\", searchData.L.Title[:min(3, len(searchData.L.Title))])\n\t\t}\n\t}\n\n\t// 3. 刷新防爬cookies（关键！访问详情页触发vrg_sc、vrg_go等防爬cookies）\n\tif DebugLog {\n\t\tfmt.Printf(\"[Gying] 刷新防爬cookies...\\n\")\n\t}","sourceCodeStart":2505,"sourceCodeEnd":2541,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/gying/gying.go#L2505-L2541","documentation":"Wraps a json.Unmarshal failure while parsing the extracted _obj.search JSON (matches[1]) into the SearchData struct. The regex found candidate JSON but its content is not valid JSON or does not fit SearchData's expected shape (e.g. type mismatch on Q/N fields).","triggerScenarios":"searchWithScraper extracts matches[1] from the page and json.Unmarshal returns an error: malformed/truncated JSON in the page, JSON field types changed (e.g. N became a number instead of string), or the regex captured the wrong span of text.","commonSituations":"Site update changed the embedded JSON structure or field types; greedy/lazy regex captured trailing HTML; page truncated mid-JSON due to response size limits or proxy issues.","solutions":["Inspect the wrapped %w error and the raw JSON printed under DebugLog to see the exact mismatch.","Update the SearchData struct to match the site's current field names/types (use json.RawMessage or flexible types).","Tighten or update searchDataPattern so it captures only the complete JSON object.","Check the site for a frontend/API update and adjust the parser accordingly."],"exampleFix":"// before\ntype SearchData struct {\n    N string `json:\"n\"`\n}\n// after — tolerate number-or-string count\ntype SearchData struct {\n    N json.Number `json:\"n\"`\n}","handlingStrategy":"try-catch","validationCode":"if len(matches) < 2 || !json.Valid(matches[1]) {\n    return errors.New(\"extracted search JSON is not valid\")\n}","typeGuard":null,"tryCatchPattern":"var searchData SearchData\nif err := json.Unmarshal(matches[1], &searchData); err != nil {\n    var ute *json.UnmarshalTypeError\n    if errors.As(err, &ute) {\n        // field type changed upstream: log field and raw payload for triage\n        log.Printf(\"field %s type mismatch, raw: %s\", ute.Field, matches[1])\n    }\n    return err\n}","preventionTips":["Use tolerant types (json.Number, json.RawMessage) for fields prone to type changes.","Keep the extraction regex tight so it captures only complete JSON.","Snapshot known-good page payloads and diff them after site updates."],"tags":["json","unmarshal","html-parsing"],"backgroundTag":"json-unmarshal-failed","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"}