{"record":{"id":"a4b8bc1028fba1d7","repo":"quickwit-oss/quickwit","slug":"failed-to-parse-host-host","errorCode":null,"errorMessage":"failed to parse host: `{host}`","messagePattern":"failed to parse host: `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-common/src/net.rs","lineNumber":125,"sourceCode":"}\n\nimpl From<Ipv6Addr> for Host {\n    fn from(ip_addr: Ipv6Addr) -> Self {\n        Host::IpAddr(IpAddr::V6(ip_addr))\n    }\n}\n\nimpl FromStr for Host {\n    type Err = anyhow::Error;\n\n    fn from_str(host: &str) -> Result<Self, Self::Err> {\n        if let Ok(ip_addr) = host.parse::<IpAddr>() {\n            return Ok(Self::IpAddr(ip_addr));\n        }\n        if is_valid_hostname(host) {\n            return Ok(Self::Hostname(host.to_string()));\n        }\n        bail!(\"failed to parse host: `{host}`\")\n    }\n}\n\n/// Represents an address `<host>:<port>` where `host` can be an IP address or a hostname.\n#[derive(Clone, Debug)]\npub struct HostAddr {\n    host: Host,\n    port: u16,\n}\n\nimpl HostAddr {\n    /// Attempts to parse a `host_addr`.\n    /// If no port is defined, it just accepts the host and uses the given default port.\n    ///\n    /// This function supports:\n    /// - IPv4\n    /// - IPv4:port\n    /// - IPv6","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-common/src/net.rs#L107-L143","documentation":"`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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Fix the host string to a valid DNS hostname: letters/digits/hyphens only, no leading/trailing hyphens, labels ≤ 63 chars.","If the host is an IP, supply it in valid form (IPv4 dotted-quad or bracketed IPv6) so it parses as `IpAddr`.","Trim whitespace and remove trailing dots from the value before parsing.","Check the surrounding config (host vs host:port) — if a port was accidentally included, split it off and use the address parser instead."],"exampleFix":"// before\nlet host: Host = \"my_searcher_1\".parse()?; // underscore invalid\n// after\nlet host: Host = \"my-searcher-1\".parse()?;","handlingStrategy":"validation","validationCode":"fn is_valid_host(s: &str) -> bool {\n    let s = s.trim().trim_end_matches('.');\n    !s.is_empty()\n        && s.len() <= 255\n        && s.split('.')\n            .all(|label| {\n                !label.is_empty()\n                    && label.len() <= 63\n                    && label.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')\n                    && !label.starts_with('-')\n                    && !label.ends_with('-')\n            })\n        || s.parse::<std::net::IpAddr>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"match host_str.parse::<quickwit_common::net::Host>() {\n    Ok(host) => use_host(host),\n    Err(e) => {\n        eprintln!(\"Invalid host '{host_str}': use letters/digits/hyphens or a valid IP ({e})\");\n    }\n}","preventionTips":["Trim whitespace and trailing dots from host inputs from config/env.","Never use underscores in hostnames; prefer hyphens for node names.","Wrap IPv6 literals in brackets when embedding in addresses.","Validate hostnames at config-load time, before the value reaches the parser."],"tags":["network","parsing","validation","hostname"],"backgroundTag":"invalid-argument-format","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}