chenhg5/cc-connect · error

wecom: invalid proxy URL %q: %w

Error message

wecom: invalid proxy URL %q: %w

What it means

The optional proxy option must be a URL that url.Parse can handle. New() parses it to build an http.ProxyURL for the platform's API client (with proxy_username/proxy_password layered on as basic auth). If parsing fails, construction aborts with the underlying url.Parse error wrapped in this message.

Source

Thrown at platform/wecom/wecom.go:169

	apiBaseURL = strings.TrimRight(strings.TrimSpace(apiBaseURL), "/")
	if apiBaseURL == "" {
		apiBaseURL = defaultAPIBaseURL
	} else {
		parsed, err := url.Parse(apiBaseURL)
		if err != nil || (parsed.Scheme != "https" && parsed.Scheme != "http") || parsed.Host == "" {
			return nil, fmt.Errorf("wecom: invalid api_base_url %q: must be a valid http(s) URL", apiBaseURL)
		}
	}

	transport := &http.Transport{
		MaxIdleConns:        2,
		MaxIdleConnsPerHost: 1,
		IdleConnTimeout:     10 * time.Second,
	}
	if proxyURL, _ := opts["proxy"].(string); proxyURL != "" {
		u, err := url.Parse(proxyURL)
		if err != nil {
			return nil, fmt.Errorf("wecom: 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)
		}
		transport.Proxy = http.ProxyURL(u)
		transport.DisableKeepAlives = true // prevent CONNECT tunnel accumulation on proxy
		slog.Info("wecom: outbound API requests will use proxy (keep-alive disabled)", "proxy", u.Host, "auth", proxyUser != "")
	}
	apiClient := &http.Client{Timeout: 30 * time.Second, Transport: transport}

	enableMarkdown, _ := opts["enable_markdown"].(bool)
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("wecom", allowFrom)

	return &Platform{
		corpID:         corpID,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the proxy URL syntax, e.g. "http://proxy.corp.local:3128", and re-test with url.Parse
  2. Remove special characters or URL-encode them (use url.UserPassword for credentials instead of inline user:pass)
  3. Verify no stray whitespace from YAML/TOML formatting survives into the value
  4. If no proxy is needed, remove the proxy option entirely

Example fix

// before
"proxy": "http ://proxy.corp:3128" // space -> url.Parse error
// after
"proxy": "http://proxy.corp:3128"
Defensive patterns

Strategy: validation

Validate before calling

proxy, _ := opts["proxy"].(string)
if proxy != "" {
	if _, err := url.Parse(strings.TrimSpace(proxy)); err != nil {
		return fmt.Errorf("proxy %q is not a valid URL: %v", proxy, err)
	}
}

Prevention

When it happens

Trigger: Setting opts["proxy"] to a malformed URL such as "http ://proxy:8080" (space), "proxy.corp:3128" without scheme (often parses but note scheme-less hosts may yield opaque errors or later failures), a control character, or an unparseable percent-encoding.

Common situations: Corporate proxy URLs copied with stray spaces or brackets; missing http:// scheme; special characters in proxy passwords that were not URL-encoded when embedded in the URL; config variable interpolation producing garbage.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


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