{"record":{"id":"9f281d1b12014955","repo":"fish2018/pansou","slug":"s-w-9f281d","errorCode":null,"errorMessage":"[%s] 解析接口配置失败: %w","messagePattern":"\\[(.+?)\\] 解析接口配置失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/yingso/yingso.go","lineNumber":202,"sourceCode":"\t\tresults = append(results, result)\n\t}\n\n\treturn plugin.FilterResultsByKeyword(results, keyword), nil\n}\n\nfunc (p *YingsoPlugin) fetchConfig(ctx context.Context, client *http.Client) (apiConfig, error) {\n\tvar response apiEnvelope[string]\n\tif err := p.requestJSON(ctx, client, http.MethodGet, p.apiBaseURL+\"/test\", nil, &response); err != nil {\n\t\treturn apiConfig{}, fmt.Errorf(\"[%s] 获取接口配置失败: %w\", p.Name(), err)\n\t}\n\tif response.Code != http.StatusOK || response.Data == \"\" {\n\t\treturn apiConfig{}, fmt.Errorf(\"[%s] 接口配置异常: code=%d msg=%s\", p.Name(), response.Code, response.Msg)\n\t}\n\n\tdecoded := xorUTF16(response.Data, bootstrapKey)\n\tvar config apiConfig\n\tif err := jsonutil.UnmarshalString(decoded, &config); err != nil {\n\t\treturn apiConfig{}, fmt.Errorf(\"[%s] 解析接口配置失败: %w\", p.Name(), err)\n\t}\n\tif config.URLVersion == \"\" || config.UserID == \"\" || config.Start < 0 || config.End <= config.Start || config.End > 24 {\n\t\treturn apiConfig{}, fmt.Errorf(\"[%s] 接口配置缺少必要字段\", p.Name())\n\t}\n\treturn config, nil\n}\n\nfunc (p *YingsoPlugin) search(ctx context.Context, client *http.Client, config apiConfig, keyword string) ([]searchItem, error) {\n\tpayload := searchPayload{\n\t\tPageSize: pageSize,\n\t\tPageNum:  1,\n\t\tTitle:    keyword,\n\t\tRoot:     0,\n\t\tCategory: \"all\",\n\t\tUserID:   config.UserID,\n\t}\n\tencrypted, err := encryptPayload(payload, config)\n\tif err != nil {","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/yingso/yingso.go#L184-L220","documentation":"The bootstrap config payload from GET /test was received and XOR-decoded with bootstrapKey, but the decoded string is not valid JSON (or is not a JSON string decodable by jsonutil.UnmarshalString), so fetchConfig cannot unmarshal it into apiConfig. This indicates the encrypted/encoded payload did not decode as expected.","triggerScenarios":"jsonutil.UnmarshalString(xorUTF16(response.Data, bootstrapKey), &config) returns an error during fetchConfig, typically because the XOR-decoded data is garbled or truncated.","commonSituations":"The bootstrapKey or xorUTF16 encoding no longer matches what the server sends after an API-side change; the server returned a non-config payload (e.g., HTML error body) that still passed the code==200 check; a proxy mangled the response body.","solutions":["Inspect the raw response.Data and the decoded string to confirm what the server actually returned","Verify bootstrapKey and the xorUTF16 scheme match the current server-side encoding","Confirm the server's /test endpoint still returns the XOR-encoded JSON config; update decoding if the contract changed","Check for proxies/CDNs rewriting the response body"],"exampleFix":"// before\ndecoded := xorUTF16(response.Data, bootstrapKey) // stale key\nc := xorUTF16Decode(data, currentBootstrapKey) // after: use the key matching the deployed API","handlingStrategy":"try-catch","validationCode":"if resp.Code == http.StatusOK && resp.Data == \"\" {\n    return errors.New(\"empty bootstrap payload; decoding will fail\")\n}","typeGuard":"func looksLikeConfig(decoded string) bool {\n    var probe map[string]json.RawMessage\n    return json.Unmarshal([]byte(decoded), &probe) == nil && len(probe) > 0\n}","tryCatchPattern":"cfg, err := p.fetchConfig(ctx, client)\nif err != nil {\n    if strings.Contains(err.Error(), \"解析接口配置失败\") {\n        log.Printf(\"bootstrap payload failed to decode; check key/encoding drift: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep bootstrapKey in sync with the deployed server encoding","Log the first bytes of the decoded string when unmarshal fails to detect HTML/garbage","Pin and monitor the API version so encoding changes are caught","Test fetchConfig against a fixture payload in CI"],"tags":["json","decoding","api","config"],"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"}