nikivdev/code · error · anyhow::Error
Host is empty
Error message
Host is empty
What it means
normalize_host sanitizes user-supplied host input before route operations. After stripping scheme prefixes and trailing slashes, if nothing remains the function bails because an empty host cannot be a valid route key.
Source
Thrown at src/domains.rs:278
println!("{}", "-".repeat(58));
for (host, target) in routes {
println!("{:<32} {}", host, target);
}
}
Ok(())
}
fn normalize_host(raw: &str) -> Result<String> {
let mut host = raw.trim().to_ascii_lowercase();
if let Some(stripped) = host.strip_prefix("http://") {
host = stripped.to_string();
} else if let Some(stripped) = host.strip_prefix("https://") {
host = stripped.to_string();
}
host = host.trim_end_matches('/').to_string();
if host.is_empty() {
bail!("Host is empty");
}
if host.contains('/') || host.contains(':') || host.contains(char::is_whitespace) {
bail!("Host must be a hostname like linsa.localhost");
}
if !host.ends_with(".localhost") {
bail!("Host must end with .localhost");
}
if host == ".localhost" || host == "localhost" {
bail!("Host must include a subdomain (for example: linsa.localhost)");
}
Ok(host)
}
fn normalize_target(raw: &str) -> Result<String> {
let mut target = raw.trim().to_string();
if let Some(stripped) = target.strip_prefix("http://") {
target = stripped.to_string();
} else if let Some(stripped) = target.strip_prefix("https://") {View on GitHub (pinned to a747e741ae)
Solutions
- Pass a full hostname such as linsa.localhost
- Check that the shell variable holding the host is actually set/non-empty
- Quote the argument so empty expansions fail loudly instead of vanishing
Example fix
// before f domains add "$HOST" :3000 # HOST empty -> Host is empty // after f domains add "linsa.localhost" :3000
Defensive patterns
Strategy: validation
Validate before calling
let host = raw.trim();
let host = host.trim_start_matches("http://").trim_start_matches("https://").trim_end_matches('/');
if host.is_empty() {
return Err("host argument required, e.g. linsa.localhost");
} Prevention
- Always pass an explicit, quoted host argument
- Check shell variables are set before expansion (${HOST:?unset})
- Reject empty strings in your own wrappers before invoking the CLI
When it happens
Trigger: Passing an empty string, only a scheme ("http://"), only slashes ("/"), or only whitespace to domains get/add/rm — everything is stripped and the result is empty.
Common situations: Shell variable expansion failing ($HOST unset), copy-pasting just "https://", or scripting the command with a missing argument that defaults to empty.
Related errors
- Host must be a hostname like linsa.localhost
- Query cannot be empty
- Host must end with .localhost
- Host must include a subdomain (for example: linsa.localhost)
- lifecycle.domains.aliases[].host is required
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/09f0f0c5b7e7a597.
Report an issue: GitHub.