Hmbown/CodeWhale · warning · anyhow::Error

host cannot be empty

Error message

host cannot be empty

What it means

Bailed by `normalize_host_arg` when the argument normalizes to an empty string. `normalize_host_for_compare` trims whitespace, strips trailing dots, lowercases, and folds a `*.` prefix into a leading dot; if nothing remains the command refuses to add an empty entry to the host list.

Source

Thrown at crates/tui/src/commands/groups/utility/network.rs:279

fn remove_host(list: &mut Vec<String>, host: &str) {
    list.retain(|existing| normalize_host_for_compare(existing) != host);
}

fn normalize_host_arg(input: &str) -> anyhow::Result<String> {
    let trimmed = input.trim();
    let host = if trimmed.starts_with("http://") || trimmed.starts_with("https://") {
        host_from_url(trimmed).context("URL must include a host")?
    } else {
        if trimmed.contains("://") || trimmed.contains('/') {
            bail!("Pass a host like `github.com`, not a URL path");
        }
        trimmed.to_string()
    };

    let normalized = normalize_host_for_compare(&host);
    if normalized.is_empty() {
        bail!("host cannot be empty");
    }
    Ok(normalized)
}

fn normalize_host_for_compare(host: &str) -> String {
    let trimmed = host.trim().trim_end_matches('.').to_ascii_lowercase();
    if let Some(rest) = trimmed.strip_prefix("*.") {
        format!(".{rest}")
    } else {
        trimmed
    }
}

fn display_list(values: &[String]) -> String {
    if values.is_empty() {
        "[]".to_string()
    } else {
        format!("[{}]", values.join(", "))

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Pass an actual hostname such as `example.com`.
  2. Use `*.example.com` to cover subdomains of a domain.
  3. Re-run the command checking for stray quotes or trailing dots in the argument.
  4. To change catch-all behavior use `/network default <allow|deny|prompt>`, never an empty host entry.

Example fix

# before
/network deny .
# after
/network deny example.com
Defensive patterns

Strategy: validation

Validate before calling

fn normalized_host_or_none(input: &str) -> Option<String> {
    let h = input.trim().trim_end_matches('.').to_ascii_lowercase();
    if h.is_empty() {
        return None;
    }
    Some(match h.strip_prefix("*.") {
        Some(rest) => format!(".{rest}"),
        None => h,
    })
}

Type guard

fn is_nonempty_host(input: &str) -> bool {
    !input.trim().trim_end_matches('.').is_empty()
}

Prevention

When it happens

Trigger: `/network allow .`, `/network deny " "`, `/network allow ...` — any argument that is only whitespace or dots after trimming. (An http(s) URL without a host hits the separate `URL must include a host` error instead.)

Common situations: Accidental empty paste from the clipboard, shell completion inserting a bare dot, or attempting to 'allow everything' by adding a dot-only entry.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/b526c6943acac348. Report an issue: GitHub.