chenhg5/cc-connect · error

%s: new request: %w

Error message

%s: new request: %w

What it means

http.NewRequestWithContext rejected the CDN download/upload URL while building the GET request in fetchCdnBytes — the assembled fullURL (from buildCdnDownloadURL/buildCdnUploadURL) is not parseable, indicating a malformed cdn_base or corrupted encrypted_query_param.

Source

Thrown at platform/weixin/cdn.go:131

	return fmt.Sprintf("%s/download?encrypted_query_param=%s",
		strings.TrimRight(cdnBase, "/"),
		url.QueryEscape(encryptedQueryParam))
}

func buildCdnUploadURL(cdnBase, uploadParam, filekey string) string {
	return fmt.Sprintf("%s/upload?encrypted_query_param=%s&filekey=%s",
		strings.TrimRight(cdnBase, "/"),
		url.QueryEscape(uploadParam),
		url.QueryEscape(filekey))
}

func fetchCdnBytes(ctx context.Context, client *http.Client, fullURL, label string) ([]byte, error) {
	if client == nil {
		client = http.DefaultClient
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, nil)
	if err != nil {
		return nil, fmt.Errorf("%s: new request: %w", label, err)
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("%s: get: %w", label, err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(io.LimitReader(resp.Body, maxWeixinMediaBytes+1))
	if err != nil {
		return nil, fmt.Errorf("%s: read: %w", label, err)
	}
	if len(body) > maxWeixinMediaBytes {
		return nil, fmt.Errorf("%s: CDN body exceeds %d bytes", label, maxWeixinMediaBytes)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: CDN http %d: %s", label, resp.StatusCode, truncateForLog(body, 256))
	}
	return body, nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Log fullURL (with the encrypted param redacted/truncated) to spot the malformed component
  2. Check the cdn_base_url configuration and the CDN parameters received from Weixin for truncation or bad escaping
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at platform/weixin/cdn.go:131 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/2571cbb132bed9d4. Report an issue: GitHub.