chenhg5/cc-connect · error

telegram: invalid proxy URL %q: %w

Error message

telegram: invalid proxy URL %q: %w

What it means

telegram.New() parses the optional 'proxy' option as a URL. If url.Parse rejects the value, construction fails with this error wrapping the parse error, because a malformed proxy address would break every subsequent HTTP request to the Telegram API.

Source

Thrown at platform/telegram/telegram.go:152

	stableConnectionWindow  = 10 * time.Second
)

func New(opts map[string]any) (core.Platform, error) {
	token, _ := opts["token"].(string)
	if token == "" {
		return nil, fmt.Errorf("telegram: token is required")
	}
	allowFrom, _ := opts["allow_from"].(string)
	core.CheckAllowFrom("telegram", allowFrom)

	// Build HTTP client with optional proxy support.
	// Timeout must exceed the server-side long-poll duration (pollTimeout − 1s = 59s)
	// to avoid the HTTP client racing with Telegram's response. 90s gives 30s headroom.
	httpClient := &http.Client{Timeout: 90 * time.Second}
	if proxyURL, _ := opts["proxy"].(string); proxyURL != "" {
		u, err := url.Parse(proxyURL)
		if err != nil {
			return nil, fmt.Errorf("telegram: 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("telegram: using proxy", "proxy", u.Host, "auth", proxyUser != "")
	}

	groupReplyAll, _ := opts["group_reply_all"].(bool)
	shareSessionInChannel, _ := opts["share_session_in_channel"].(bool)
	enableReactions, _ := opts["enable_reactions"].(bool)

	// Default to "compact" so streaming edits work out of the box. Telegram has
	// no rich card UI, so "card" is normalized to "compact". Users can opt out
	// via progress_style = "legacy" to restore the old "send full text once"
	// behavior.

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the proxy URL in config, e.g. proxy = "socks5://127.0.0.1:1080" or "http://proxy:8080"
  2. Bracket IPv6 hosts: "http://[::1]:8080"
  3. Read the wrapped %w parse error to see the exact offending character
  4. Remove the proxy option entirely if no proxy is needed

Example fix

// before
proxy = "127.0.0.1:1080"
# after
proxy = "socks5://127.0.0.1:1080"
Defensive patterns

Strategy: validation

Validate before calling

if raw := opts["proxy"]; raw != "" {
    if _, err := url.Parse(raw); err != nil { return err }
}

Try / catch

p, err := telegram.New(opts)
if err != nil {
    slog.Error("telegram init failed (check proxy URL)", "err", err)
    return err
}

Prevention

When it happens

Trigger: Calling telegram.New(opts) with opts["proxy"] set to a string that url.Parse cannot parse, e.g. "http://[bad-ipv6", "::1:8080", or a value with stray control characters / spaces.

Common situations: Proxy URL copied with surrounding quotes or whitespace into config.toml; missing scheme confusion; hand-edited config introducing invalid characters; IPv6 proxy not bracketed correctly.

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/ef6af64e5dc14530. Report an issue: GitHub.