BigPizzaV3/CodexPlusPlus · error

Base URL 缺少主机名

Error message

Base URL 缺少主机名

What it means

After the URL parses, validate_llm_proxy_url requires a host component. Certain parseable URLs — e.g. "https://" alone, or scheme-only forms — yield no host, so url.host_str() returns None and the library raises this error. This prevents issuing requests to a hostless URL.

Solutions

  1. Provide a complete URL with hostname, e.g. "https://api.example.com/v1".
  2. Re-copy the provider base URL from the vendor docs and trim truncation.
  3. Check config.toml / saved profile for a partially written base_url value and fix it.
  4. Add client-side validation requiring a non-empty host before submitting.

Example fix

// before
"base_url": "https://"
// after
"base_url": "https://api.deepseek.com/v1"
Defensive patterns

Strategy: validation

Validate before calling

function hasHost(raw: string): boolean {
  try { return new URL(raw.trim()).hostname.length > 0; }
  catch { return false; }
}

Try / catch

try {
  await api.setLlmProxy({ baseUrl });
} catch (e) {
  if (String(e).includes('缺少主机名')) {
    showFieldError('base_url', 'URL 缺少主机名,请填写完整地址');
  } else { throw e; }
}

Prevention

When it happens

Trigger: Passing "https://", "https:///path", or a URL whose host part is empty/invalid to the LLM proxy Base URL field via llm_proxy_value.

Common situations: Truncated paste of a base URL into the profile form; config file edited by hand dropping the host; programmatic config generation bug concatenating scheme and path only.

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 BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/8da1ed3170afc981. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/routes.rs:794

        "status": "ok",
        "http_status": http_status,
        "ok": ok,
        "body_text": body_text,
        "body_json": body_json,
    }))
}

fn validate_llm_proxy_url(raw: &str) -> anyhow::Result<reqwest::Url> {
    let url = reqwest::Url::parse(raw.trim()).map_err(|_| anyhow::anyhow!("Base URL 格式无效"))?;
    if url.scheme() != "https" {
        anyhow::bail!("Base URL 必须使用 HTTPS");
    }
    if !url.username().is_empty() || url.password().is_some() {
        anyhow::bail!("Base URL 不得包含用户名或密码");
    }
    let host = url
        .host_str()
        .ok_or_else(|| anyhow::anyhow!("Base URL 缺少主机名"))?;
    if is_blocked_llm_proxy_host(host) {
        anyhow::bail!("Base URL 不得指向本机或私有网络");
    }
    Ok(url)
}

fn is_blocked_llm_proxy_host(host: &str) -> bool {
    let host = host
        .trim()
        .trim_start_matches('[')
        .trim_end_matches(']')
        .to_lowercase();
    if host.is_empty()
        || host == "localhost"
        || host.ends_with(".localhost")
        || host.ends_with(".local")
    {
        return true;

View on GitHub (pinned to b1ed92e5e4)