xai-org/grok-build · error
Invalid proxy port in '{url}'
Error message
Invalid proxy port in '{url}' What it means
parse_proxy_url splits a proxy URL into host and port. When an explicit port is present after the last ':' it is parsed as u16; if parsing fails (non-numeric, empty, or out of range) this error is thrown.
Source
Thrown at crates/codegen/xai-grok-shell/src/agent/proxy.rs:235
///
/// Accepted formats:
/// - `http://host:port`
/// - `http://host` (defaults to port 80)
/// - `host:port`
fn parse_proxy_url(url: &str) -> anyhow::Result<(String, u16)> {
// Strip scheme if present.
let without_scheme = url
.strip_prefix("http://")
.or_else(|| url.strip_prefix("https://"))
.unwrap_or(url);
// Strip trailing path/slash.
let authority = without_scheme.split('/').next().unwrap_or(without_scheme);
if let Some((host, port_str)) = authority.rsplit_once(':') {
let port: u16 = port_str
.parse()
.map_err(|_| anyhow::anyhow!("Invalid proxy port in '{url}'"))?;
Ok((host.to_string(), port))
} else {
// No port — default to 80 for HTTP proxies.
Ok((authority.to_string(), 80))
}
}
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
// ===== parse_proxy_url =====
View on GitHub (pinned to bc7f02eddd)
Solutions
- Check the proxy URL env/config value and fix the port to a valid number 1-65535
- Omit the port entirely to default to 80
- For IPv6 proxies use a form the parser accepts (bracketed host without stray colons after authority extraction) or fix the parser to use url::Url parsing
- Add a unit test for the failing URL string before changing config
Example fix
// before let proxy = "http://proxy.corp:8.8.8.8"; // invalid port // after let proxy = "http://proxy.corp:8080";
Defensive patterns
Strategy: validation
Validate before calling
fn valid_proxy(s: &str) -> bool {
let authority = s.trim_start_matches("http://").trim_start_matches("https://").split('/').next().unwrap_or("");
match authority.rsplit_once(':') {
Some((_, p)) => p.parse::<u16>().is_ok(),
None => !authority.is_empty(),
}
}
// call before passing proxy_url to the library Try / catch
match parse_proxy_url(&url) {
Ok((host, port)) => { /* ... */ }
Err(e) => eprintln!("fix proxy config: {e}"),
} Prevention
- Validate proxy URLs at config load time, not at connect time
- Prefer url::Url::parse over manual string splitting for proxy config
- Document that omitting the port defaults to 80
When it happens
Trigger: PROXY_URL like 'http://proxy:abc', 'proxy.corp:', 'http://proxy:99999' (>65535), or any string with a colon followed by garbage after the scheme is stripped.
Common situations: Typo in proxy config, shell-expanded empty variable producing 'http://proxy:', copy-pasting a URL that includes ':/', or IPv6 addresses whose extra colons confuse the naive rsplit_once(':') split.
Related errors
- unknown key notation: <{notation}>
- Session does not exist locally (session registry is disabled
- The change was applied, but Doctor still reports `{}`.
- The change was applied, but Doctor could not verify `{}` in
- Invalid environment variable format: '{pair}'. Environment v
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/07a71bd55e358430.
Report an issue: GitHub.