{"record":{"id":"0fa3b7de3e07d842","repo":"chenhg5/cc-connect","slug":"empty-qrcode-img-content-from-server","errorCode":null,"errorMessage":"empty qrcode_img_content from server","messagePattern":"empty qrcode_img_content from server","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/weixin.go","lineNumber":265,"sourceCode":"\tIlinkUserID string\n}\n\nfunc runWeixinQRLoginFlow(opts weixinQRLoginOptions) (*weixinQRLoginResult, error) {\n\tif opts.Timeout < time.Second {\n\t\topts.Timeout = 480 * time.Second\n\t}\n\tbotType := opts.BotType\n\tif botType == \"\" {\n\t\tbotType = defaultWeixinBotType\n\t}\n\n\tctx := context.Background()\n\tqrPayload, err := weixinFetchBotQRCode(ctx, opts.APIBaseURL, botType, opts.RouteTag, opts.Debug)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif strings.TrimSpace(qrPayload.QRCodeImgContent) == \"\" {\n\t\treturn nil, fmt.Errorf(\"empty qrcode_img_content from server\")\n\t}\n\n\tqrURL := strings.TrimSpace(qrPayload.QRCodeImgContent)\n\tfmt.Println(\"请使用微信扫描下方二维码（或打开 URL）以连接 ilink 机器人：\")\n\tfmt.Printf(\"URL: %s\\n\\n\", qrURL)\n\ttryPrintTerminalQRCode(qrURL)\n\tif opts.QRImage != \"\" {\n\t\tif err := saveQRCodeImage(qrURL, opts.QRImage); err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"Warning: failed to save QR image: %v\\n\", err)\n\t\t} else {\n\t\t\tfmt.Printf(\"QR code saved to: %s\\n\\n\", opts.QRImage)\n\t\t}\n\t}\n\n\tdeadline := time.Now().Add(opts.Timeout)\n\tqrKey := qrPayload.QRCode\n\trefreshCount := 1\n\tscannedPrinted := false","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/weixin.go#L247-L283","documentation":"runWeixinQRLoginFlow fetches a login QR code from the WeChat/ilink bot server via weixinFetchBotQRCode. Even on success, the server may return a payload whose qrcode_img_content is blank; the code rejects it with \"empty qrcode_img_content from server\" because there is no URL to render or poll against. This indicates a malformed or degraded server response rather than a client-side mistake.","triggerScenarios":"`cc-connect weixin setup` in new/QR mode → runWeixinQRLoginFlow → weixinFetchBotQRCode returns success (no transport error) but qrPayload.QRCodeImgContent is empty or whitespace-only after TrimSpace.","commonSituations":"WeChat/ilink backend incident or maintenance returning 200 with an empty body; wrong APIBaseURL pointing at a stub/mock server; API contract change after a server upgrade; rate limiting that silently empties the QR payload.","solutions":["Simply retry `cc-connect weixin setup` — transient backend issues often resolve on a second attempt.","Verify --api-base-url / APIBaseURL points at the correct production endpoint.","Enable debug mode (opts.Debug) or inspect the raw HTTP response to confirm what the server returned.","Check the weixin/ilink service status or changelog for API contract changes to qrcode_img_content.","If persisting, report the issue with the request/response captured in debug output."],"exampleFix":"// before (trust any 200)\nqrPayload, err := weixinFetchBotQRCode(ctx, opts.APIBaseURL, ...)\nif err != nil { return nil, err }\n\n// after (guard empties with retry)\nfor attempt := 0; attempt < 3; attempt++ {\n    qrPayload, err := weixinFetchBotQRCode(ctx, opts.APIBaseURL, ...)\n    if err == nil && strings.TrimSpace(qrPayload.QRCodeImgContent) != \"\" {\n        break\n    }\n    time.Sleep(2 * time.Second)\n}","handlingStrategy":"retry","validationCode":"qr, err := weixinFetchBotQRCode(ctx, apiBase, botType, routeTag, debug)\nif err == nil && strings.TrimSpace(qr.QRCodeImgContent) == \"\" {\n    // treat as retryable upstream error before starting the poll loop\n}","typeGuard":null,"tryCatchPattern":"qrPayload, err := runWeixinQRLoginFlow(ctx, opts)\nif err != nil && strings.Contains(err.Error(), \"empty qrcode_img_content\") {\n    time.Sleep(2 * time.Second)\n    qrPayload, err = runWeixinQRLoginFlow(ctx, opts) // one retry\n}","preventionTips":["Retry setup once before investigating when the server returns empty QR content","Pin APIBaseURL to the documented production endpoint","Enable debug logging to capture raw responses for upstream bug reports","Monitor ilink service status during maintenance windows"],"tags":["weixin","qrcode","api"],"backgroundTag":"empty-api-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}