chenhg5/cc-connect · error

weixin: invalid proxy URL %q: %w

Error message

weixin: invalid proxy URL %q: %w

What it means

New reads the optional "proxy" option and parses it with url.Parse before wiring it into the HTTP client. If the proxy string is not a valid URL, construction aborts with this wrapped error naming the offending value.

Source

Thrown at platform/weixin/weixin.go:216

		burstWindow = 0
	}

	dataDir, _ := opts["cc_data_dir"].(string)
	project, _ := opts["cc_project"].(string)
	stateDir := ""
	if dataDir != "" && project != "" {
		safeProj := sanitizePathSegment(project)
		stateDir = filepath.Join(dataDir, "weixin", safeProj, sanitizePathSegment(accountLabel))
	}
	if override, _ := opts["state_dir"].(string); strings.TrimSpace(override) != "" {
		stateDir = strings.TrimSpace(override)
	}

	httpClient := &http.Client{Timeout: defaultAPITimeout}
	if proxyURL, _ := opts["proxy"].(string); proxyURL != "" {
		u, err := url.Parse(proxyURL)
		if err != nil {
			return nil, fmt.Errorf("weixin: invalid proxy URL %q: %w", proxyURL, err)
		}
		proxyUser, _ := opts["proxy_username"].(string)
		proxyPass, _ := opts["proxy_password"].(string)
		if proxyUser != "" {
			u.User = url.UserPassword(proxyUser, proxyPass)
		}
		httpClient.Transport = &http.Transport{Proxy: http.ProxyURL(u)}
		slog.Info("weixin: using proxy", "proxy", u.Redacted())
	}

	// CDN 客户端:微信国内 CDN 必须直连,绕过环境变量中的代理(如 HTTPS_PROXY)
	cdnHttpClient := &http.Client{
		Timeout:   60 * time.Second,
		Transport: &http.Transport{Proxy: nil},
	}

	if burstLimit <= 0 {
		burstLimit = defaultBurstLimit

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Add an explicit scheme to the proxy value, e.g. "http://127.0.0.1:7890" or "socks5://..."
  2. Trim quotes/whitespace from the configured proxy string
  3. Check the wrapped inner url.Parse error for the exact parse failure position

Example fix

// before
"proxy": "127.0.0.1:7890"
// after
"proxy": "http://127.0.0.1:7890"
Defensive patterns

Strategy: validation

Validate before calling

if raw, _ := opts["proxy"].(string); raw != "" {
    if _, err := url.Parse(strings.TrimSpace(raw)); err != nil {
        return fmt.Errorf("bad weixin proxy %q: %w", raw, err)
    }
}

Try / catch

p, err := weixin.New(opts)
if err != nil && strings.Contains(err.Error(), "invalid proxy URL") {
    return fmt.Errorf("fix proxy in config: %w", err)
}

Prevention

When it happens

Trigger: weixin.New is given opts["proxy"] set to a malformed URL, e.g. "127.0.0.1:7890" without a scheme, or a string with illegal characters/spaces.

Common situations: Proxy configured without http:// or socks5:// scheme; copied proxy string includes surrounding quotes or whitespace; config value built from env vars that contain invalid characters.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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