nikivdev/code · error · anyhow::Error

Host must be a hostname like linsa.localhost

Error message

Host must be a hostname like linsa.localhost

What it means

normalize_host enforces that hosts are plain hostnames. If the sanitized input still contains a slash, a colon (port/scheme), or whitespace, it cannot be a hostname key, so the command bails with this example-formatted message.

Source

Thrown at src/domains.rs:281

        }
    }

    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://") {
        target = stripped.to_string();
    }
    target = target.trim_end_matches('/').to_string();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Remove any port, path, or scheme — pass only the bare hostname
  2. Put the port in the target argument instead (e.g. `f domains add linsa.localhost :3000`)
  3. Trim the input string before invoking the command

Example fix

// before
f domains add linsa.localhost:3000
// after
f domains add linsa.localhost :3000
Defensive patterns

Strategy: validation

Validate before calling

let h = raw.trim().trim_start_matches("http://").trim_start_matches("https://").trim_end_matches('/');
if h.contains('/') || h.contains(':') || h.contains(char::is_whitespace) {
    return Err("pass a bare hostname like linsa.localhost (no port/path/spaces)");
}

Prevention

When it happens

Trigger: Passing values like "linsa.localhost:3000", "linsa.localhost/", "http://linsa.localhost/x", or a host containing spaces to domains get/add/rm.

Common situations: Including the port with the host (ports belong in the target), pasting a full URL with a path, or accidental whitespace from shell quoting.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/3fb48c44aae82fd5. Report an issue: GitHub.