ducaale/xh · error

Unknown protocol to set a proxy for

Error message

Unknown protocol to set a proxy for: {}

What it means

After parsing the proxy URL, the --proxy FromStr matches the protocol key (lowercased) against http/https/all. Any other key is rejected with this error because reqwest's Proxy type has no constructor for it.

Solutions

  1. Use one of the supported keys: http, https, or all (e.g. --proxy all:http://proxy:8080)
  2. Check the tool version/docs for SOCKS support before using a socks key; if unavailable, route via an HTTP CONNECT proxy instead
  3. Remember the key is lowercased, so 'HTTP' works but 'socks' does not

Example fix

// before
xh --proxy socks5:socks5://127.0.0.1:1080 GET https://example.com
// after
xh --proxy all:http://127.0.0.1:8080 GET https://example.com
Defensive patterns

Strategy: validation

Validate before calling

fn validate_proxy_protocol(arg: &str) -> Result<(), String> {
    let (protocol, _) = arg.split_once(':').ok_or("missing ':'")?;
    if !matches!(protocol.to_lowercase().as_str(), "http" | "https" | "all") {
        return Err(format!("protocol '{}' unsupported; use http|https|all", protocol));
    }
    Ok(())
}

Try / catch

match ProxyArg::from_str(&arg) {
    Ok(p) => p,
    Err(e) if e.to_string().contains("Unknown protocol") =>
        eprintln!("Use --proxy all:<url> or http/https; SOCKS is not supported"),
    Err(e) => eprintln!("--proxy rejected: {e}"),
}

Prevention

When it happens

Trigger: Passing --proxy socks5:socks5://127.0.0.1:1080 or --proxy ftp:... — any PROTOCOL key that is not http, https, or all.

Common situations: Users expecting SOCKS proxy support, mimicking curl's --proxy semantics which takes just a URL, or using keys like 'http_proxy' or 'ALL'.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of ducaale/xh@2404aceecc (2026-09-13). Data as JSON: /api/errors/99011c027a3c599f. Report an issue: GitHub.

Appendix: source

Thrown at src/cli.rs:1243

    fn from_str(s: &str) -> anyhow::Result<Self> {
        let split_arg: Vec<&str> = s.splitn(2, ':').collect();
        match split_arg[..] {
            [protocol, url] => {
                let url = reqwest::Url::try_from(url).map_err(|e| {
                    anyhow!(
                        "Invalid proxy URL '{}' for protocol '{}': {}",
                        url,
                        protocol,
                        e
                    )
                })?;

                match protocol.to_lowercase().as_str() {
                    "http" => Ok(Proxy::Http(url)),
                    "https" => Ok(Proxy::Https(url)),
                    "all" => Ok(Proxy::All(url)),
                    _ => Err(anyhow!("Unknown protocol to set a proxy for: {}", protocol)),
                }
            }
            _ => Err(anyhow!(
                "The value passed to --proxy should be formatted as <PROTOCOL>:<PROXY_URL>"
            )),
        }
    }
}

#[derive(Debug, Clone)]
pub struct Resolve {
    pub domain: String,
    pub addr: IpAddr,
}

impl FromStr for Resolve {
    type Err = anyhow::Error;

View on GitHub (pinned to 2404aceecc)