quickwit-oss/quickwit · error

failed to parse host: `{host}`

Error message

failed to parse host: `{host}`

What it means

`Host::from_str` in quickwit-common's net module accepts either a parseable IP address or a string passing `is_valid_hostname` (RFC-style hostname checks: allowed chars, label length limits, no leading/trailing hyphens). Any other string is rejected with this error. It is thrown at parse time to catch malformed host inputs early, before they are used to build addresses or URIs.

Source

Thrown at quickwit/quickwit-common/src/net.rs:125

}

impl From<Ipv6Addr> for Host {
    fn from(ip_addr: Ipv6Addr) -> Self {
        Host::IpAddr(IpAddr::V6(ip_addr))
    }
}

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

    fn from_str(host: &str) -> Result<Self, Self::Err> {
        if let Ok(ip_addr) = host.parse::<IpAddr>() {
            return Ok(Self::IpAddr(ip_addr));
        }
        if is_valid_hostname(host) {
            return Ok(Self::Hostname(host.to_string()));
        }
        bail!("failed to parse host: `{host}`")
    }
}

/// Represents an address `<host>:<port>` where `host` can be an IP address or a hostname.
#[derive(Clone, Debug)]
pub struct HostAddr {
    host: Host,
    port: u16,
}

impl HostAddr {
    /// Attempts to parse a `host_addr`.
    /// If no port is defined, it just accepts the host and uses the given default port.
    ///
    /// This function supports:
    /// - IPv4
    /// - IPv4:port
    /// - IPv6

View on GitHub (pinned to a39730c5cd)

Solutions

  1. Fix the host string to a valid DNS hostname: letters/digits/hyphens only, no leading/trailing hyphens, labels ≤ 63 chars.
  2. If the host is an IP, supply it in valid form (IPv4 dotted-quad or bracketed IPv6) so it parses as `IpAddr`.
  3. Trim whitespace and remove trailing dots from the value before parsing.
  4. Check the surrounding config (host vs host:port) — if a port was accidentally included, split it off and use the address parser instead.

Example fix

// before
let host: Host = "my_searcher_1".parse()?; // underscore invalid
// after
let host: Host = "my-searcher-1".parse()?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_host(s: &str) -> bool {
    let s = s.trim().trim_end_matches('.');
    !s.is_empty()
        && s.len() <= 255
        && s.split('.')
            .all(|label| {
                !label.is_empty()
                    && label.len() <= 63
                    && label.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')
                    && !label.starts_with('-')
                    && !label.ends_with('-')
            })
        || s.parse::<std::net::IpAddr>().is_ok()
}

Try / catch

match host_str.parse::<quickwit_common::net::Host>() {
    Ok(host) => use_host(host),
    Err(e) => {
        eprintln!("Invalid host '{host_str}': use letters/digits/hyphens or a valid IP ({e})");
    }
}

Prevention

When it happens

Trigger: Passing a string like `"my_host"` (underscore), `"-badhost"` (leading hyphen), `""` (empty), a label longer than 63 chars, or a total name over 255 chars to `Host::from_str`, `"host".parse::<Host>()`, or APIs that parse hosts internally (e.g. config fields, node addresses).

Common situations: Typos in quickwit config files (underscores in hostnames, stray spaces), copying hostnames with trailing dots or whitespace, IPv6 addresses entered without brackets in host-only fields, environment-specific DNS names that violate RFC rules.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08). Data as JSON: /api/errors/a4b8bc1028fba1d7. Report an issue: GitHub.