wavetermdev/waveterm · error

invalid proxy URL: %w

Error message

invalid proxy URL: %w

What it means

MakeHTTPClient configures an http.Client with an optional proxy. It throws this error when the supplied proxyURL cannot be parsed by net/url.Parse. Note url.Parse is lenient, so this usually means a truly malformed URL (control characters, invalid percent-encoding, unparseable scheme).

Source

Thrown at pkg/aiusechat/aiutil/aiutil.go:200

	encoder.SetEscapeHTML(false)
	err := encoder.Encode(reqBody)
	if err != nil {
		return buf, err
	}
	return buf, nil
}

func MakeHTTPClient(proxyURL string) (*http.Client, error) {
	client := &http.Client{
		Timeout: 0, // rely on ctx; streaming can be long
	}
	if proxyURL == "" {
		return client, nil
	}

	pURL, err := url.Parse(proxyURL)
	if err != nil {
		return nil, fmt.Errorf("invalid proxy URL: %w", err)
	}
	client.Transport = &http.Transport{
		Proxy: http.ProxyURL(pURL),
	}
	return client, nil
}

func IsOpenAIReasoningModel(model string) bool {
	m := strings.ToLower(model)
	return CheckModelPrefix(m, "o1") ||
		CheckModelPrefix(m, "o3") ||
		CheckModelPrefix(m, "o4") ||
		CheckModelPrefix(m, "gpt-5") ||
		CheckModelSubPrefix(m, "gpt-5.") ||
		CheckModelPrefix(m, "gpt-6") ||
		CheckModelSubPrefix(m, "gpt-6.")
}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Fix the proxy URL string to a valid absolute URL, e.g. "http://host:port" or "socks5://host:port".
  2. Check the wrapped url.Parse error (errors.Unwrap / %w chain) for the exact parse failure.
  3. URL-encode any special characters in the userinfo portion (use url.UserPassword).
  4. Clear the proxy setting to run without a proxy if one is not required.
  5. Pre-validate with url.Parse in your config-loading code and fail fast with a clear message.

Example fix

// before
client, err := aiutil.MakeHTTPClient("http://proxy myhost:8080") // invalid
// after
client, err := aiutil.MakeHTTPClient("http://myhost:8080")
Defensive patterns

Strategy: validation

Validate before calling

func validateProxy(u string) error {
    if u == "" { return nil }
    if _, err := url.Parse(u); err != nil { return fmt.Errorf("bad proxy %q: %w", u, err) }
    return nil
}
// run at config-load time

Try / catch

client, err := aiutil.MakeHTTPClient(proxy)
if err != nil {
    return nil, fmt.Errorf("check your proxy configuration: %w", err)
}

Prevention

When it happens

Trigger: Calling MakeHTTPClient (via RunAnthropicChatStep/RunGeminiChatStep/RunOpenAIChatStep/RunChatStep) with a proxy URL string that url.Parse rejects — e.g. containing raw control characters or invalid escape sequences like "http://proxy:%zz".

Common situations: Misconfigured proxy settings in config files or environment (WAVE_AI_PROXY-style settings); typos in the proxy address; copy-pasted proxies with embedded whitespace/control characters; IPv6 literals unbracketed in some contexts.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/436e06c27e9c766b. Report an issue: GitHub.