Hmbown/CodeWhale · error

Codewhale account API base URL must include a host

Error message

Codewhale account API base URL must include a host

What it means

Thrown while validating the Codewhale account API base URL. After confirming the URL has no path, the validator requires a host component; a URL that parsed but has no host (e.g. a scheme-relative or opaque URL) cannot be used as an API origin, so this error is raised before the HTTPS/loopback scheme check.

Solutions

  1. Set the base URL to a full origin such as `https://api.example.com` (scheme + host, no path).
  2. Check the config file/env var for truncation or empty interpolation producing `https://`.
  3. Ensure HTTPS is used (loopback HTTP is permitted only for local testing).

Example fix

// before
api_base_url = "https://"
// after
api_base_url = "https://api.codewhale.dev"
Defensive patterns

Strategy: validation

Validate before calling

let u = url::Url::parse(base)?;
if u.host_str().is_none() || !matches!(u.path(), "" | "/") { bail!("base URL must be an origin with a host"); }

Type guard

fn is_valid_origin(u: &url::Url) -> bool {
    u.host_str().is_some() && matches!(u.path(), "" | "/")
}

Try / catch

match configure_base_url(input) {
    Err(e) if e.to_string().contains("must include a host") => { /* re-prompt for full origin */ }
    other => other?,
}

Prevention

When it happens

Trigger: Configuring the Codewhale account API base URL with a value that has no host — e.g. `"https://"`, an empty/whitespace-derived parse, or an incorrectly formed URL string.

Common situations: Typo or truncated URL in config; env var interpolation leaving an empty value; copy-paste dropping the hostname; using a bare scheme without authority.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/8b4d3dc218c3d339. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/cloud.rs:1028

struct ValidatedApiBase {
    url: Url,
    display: String,
}

fn validate_api_base(value: &str) -> Result<ValidatedApiBase> {
    let mut url = Url::parse(value.trim()).context("invalid Codewhale account API base URL")?;
    if !url.username().is_empty() || url.password().is_some() {
        bail!("Codewhale account API base URL must not contain credentials");
    }
    if url.query().is_some() || url.fragment().is_some() {
        bail!("Codewhale account API base URL must not contain a query or fragment");
    }
    if !matches!(url.path(), "" | "/") {
        bail!("Codewhale account API base URL must be an origin without a path");
    }
    let host = url
        .host_str()
        .ok_or_else(|| anyhow!("Codewhale account API base URL must include a host"))?;
    let allowed = url.scheme() == "https" || (url.scheme() == "http" && is_loopback_host(host));
    if !allowed {
        bail!(
            "Codewhale account API base URL must use HTTPS (loopback HTTP is allowed for testing)"
        );
    }
    url.set_path("/");
    let display = url.as_str().trim_end_matches('/').to_string();
    Ok(ValidatedApiBase { url, display })
}

fn validate_verification_url(
    value: &str,
    api_base: &str,
    user_code: &str,
    complete: bool,
) -> Result<String> {
    let url =

View on GitHub (pinned to 73e0f67d83)