chenhg5/cc-connect · error

discord: invalid proxy URL %q: %w

Error message

discord: invalid proxy URL %q: %w

What it means

The Discord adapter parses the optional "proxy" option as a URL at construction time; if url.Parse fails, New wraps and returns the parse error together with the offending string. This catches syntactically invalid proxy URLs before any connection is attempted.

Source

Thrown at platform/discord/discord.go:122

	progressStyle := "compact"
	if v, ok := opts["progress_style"].(string); ok {
		switch strings.ToLower(strings.TrimSpace(v)) {
		case "":
			// keep default
		case "legacy":
			progressStyle = "legacy"
		case "compact", "card":
			progressStyle = strings.ToLower(strings.TrimSpace(v))
		default:
			return nil, fmt.Errorf("discord: invalid progress_style %q (want legacy, compact, or card)", v)
		}
	}

	var proxyU *url.URL
	if proxyStr, _ := opts["proxy"].(string); proxyStr != "" {
		u, err := url.Parse(proxyStr)
		if err != nil {
			return nil, fmt.Errorf("discord: invalid proxy URL %q: %w", proxyStr, err)
		}
		if user, _ := opts["proxy_username"].(string); user != "" {
			pass, _ := opts["proxy_password"].(string)
			u.User = url.UserPassword(user, pass)
		}
		proxyU = u
	}

	base := &Platform{
		token:                      token,
		allowFrom:                  allowFrom,
		guildID:                    guildID,
		progressStyle:              progressStyle,
		groupReplyAllGuilds:        groupReplyAllGuilds,
		shareSessionInChannel:      shareSessionInChannel,
		readyCh:                    make(chan struct{}),
		threadIsolation:            threadIsolation,
		respondToAtEveryoneAndHere: respondToAtEveryoneAndHere,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Fix the proxy URL in the discord platform config so it parses, e.g. "http://127.0.0.1:7890" or "socks5://user:pass@host:1080".
  2. Percent-encode special characters (spaces, %, non-ASCII) in the URL.
  3. Remove the proxy option if no proxy is needed.
  4. Test the string first with a quick url.Parse in Go or a URI validator to see the exact parse error.

Example fix

// before
proxy = "127.0.0.1:7890::socks"

// after
proxy = "socks5://127.0.0.1:7890"
Defensive patterns

Strategy: validation

Validate before calling

if v, _ := opts["proxy"].(string); v != "" {
    if _, err := url.Parse(v); err != nil {
        log.Fatalf("invalid discord proxy URL %q: %v", v, err)
    }
}

Try / catch

p, err := discord.New(opts)
if err != nil && strings.Contains(err.Error(), "invalid proxy URL") {
    log.Fatalf("fix proxy option: %v", err)
}

Prevention

When it happens

Trigger: Calling discord.New(opts) where opts["proxy"] is a string that url.Parse rejects — e.g. "http://[bad-ipv6", "::9090" (ambiguous colon), or control characters in the URL.

Common situations: Hand-edited config.toml with a malformed proxy address; missing scheme combined with stray colons; copied proxy URL containing spaces or hidden characters; env-specific proxy injected with wrong format.

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