chenhg5/cc-connect · error
refresh QR: %w
Error message
refresh QR: %w
What it means
When the polled login QR status is "expired", runWeixinQRLoginFlow fetches a replacement QR via weixinFetchBotQRCode. If that refresh HTTP call fails, the flow aborts with "refresh QR: %w" wrapping the underlying error. The original QR is already dead at this point, so the login session cannot continue.
Source
Thrown at cmd/cc-connect/weixin.go:342
}
time.Sleep(time.Second)
continue
case "scaned":
if !scannedPrinted {
fmt.Println("\n已扫码,请在手机上确认登录…")
scannedPrinted = true
}
time.Sleep(time.Second)
continue
case "expired":
refreshCount++
if refreshCount > weixinMaxQRRefresh {
return nil, fmt.Errorf("二维码多次过期,请重试 setup")
}
fmt.Printf("\n二维码已过期,正在刷新 (%d/%d)…\n", refreshCount, weixinMaxQRRefresh)
newQR, err := weixinFetchBotQRCode(ctx, opts.APIBaseURL, botType, opts.RouteTag, opts.Debug)
if err != nil {
return nil, fmt.Errorf("refresh QR: %w", err)
}
qrKey = newQR.QRCode
qrFetchedAt = time.Now()
scannedPrinted = false
newURL := strings.TrimSpace(newQR.QRCodeImgContent)
if newURL != "" {
fmt.Println("请扫描新二维码:")
fmt.Printf("URL: %s\n\n", newURL)
tryPrintTerminalQRCode(newURL)
}
// 过期刷新时同步更新 QR 图片文件
if opts.QRImage != "" {
if err := saveQRCodeImage(newURL, opts.QRImage); err != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to update QR image: %v\n", err)
} else {
fmt.Printf("QR code updated at: %s\n\n", opts.QRImage)
}
}View on GitHub (pinned to 4000b2338a)
Solutions
- Read the wrapped root cause (%w) — fix the underlying network/API issue it names.
- Retry `cc-connect weixin setup`; transient network errors usually clear.
- Verify APIBaseURL and RouteTag configuration are correct and reachable (curl the endpoint).
- Check for ilink service incidents or rate limits; wait and retry.
- Alternatively use `cc-connect weixin bind --token ...` to skip the QR flow.
Example fix
// before: single refresh attempt, hard fail
newQR, err := weixinFetchBotQRCode(ctx, ...)
if err != nil { return nil, fmt.Errorf("refresh QR: %w", err) }
// after: bounded retry with backoff
var newQR *qrPayload
for i := 0; i < 3; i++ {
newQR, err = weixinFetchBotQRCode(ctx, ...)
if err == nil { break }
time.Sleep(time.Duration(1<<i) * time.Second)
}
if err != nil { return nil, fmt.Errorf("refresh QR: %w", err) } Defensive patterns
Strategy: retry
Validate before calling
// Pre-flight the endpoint before starting the QR flow:
resp, err := http.Head(apiBaseURL + healthPath)
if err != nil || resp.StatusCode >= 500 {
return fmt.Errorf("API endpoint %s unhealthy, aborting QR setup", apiBaseURL)
} Try / catch
res, err := runWeixinQRLoginFlow(ctx, opts)
if err != nil {
var wrapped error
if strings.Contains(err.Error(), "refresh QR:") {
wrapped = err // network blip mid-flow; safe to retry the whole setup
}
return retrySetup(wrapped)
} Prevention
- Ensure stable connectivity (avoid flaky VPN/proxy) before running setup
- Validate APIBaseURL with a quick health check first
- Implement bounded exponential backoff for the refresh fetch
- Fall back to token-based bind when the network is unreliable
When it happens
Trigger: Mid-setup, the QR expires; the automatic refresh call weixinFetchBotQRCode(ctx, opts.APIBaseURL, botType, opts.RouteTag, opts.Debug) returns a network/API error (DNS failure, timeout, 5xx, auth rejection).
Common situations: Flaky network or VPN drop during setup; ilink API outage or rate limiting that begins mid-session; misconfigured APIBaseURL that intermittently fails; corporate proxy killing long-lived sessions.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- empty qrcode_img_content from server
- 二维码多次过期,请重试 setup
- http %d: %s
- get_bot_qrcode: %w
- %s: CDN upload failed after %d attempts: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/47b50df01edccf29.
Report an issue: GitHub.