openai/codex · error · anyhow::Error

host must not be empty

Error message

host must not be empty

What it means

normalize_hook_host runs each hook's host through normalize_host (the trim/lowercase normalization used for hook lookup) and rejects hosts that normalize to nothing with 'host must not be empty'. Inside validate_mitm_hook_config the failure is wrapped as 'invalid network.mitm_hooks[i].host: host must not be empty', so the offending hook's index is visible in the anyhow context chain.

Source

Thrown at codex-rs/network-proxy/src/mitm_hook.rs:539

fn compile_glob_matcher(pattern: &str, literal_separator: bool) -> Result<CompiledGlobMatcher> {
    let mut builder = GlobBuilder::new(pattern);
    builder
        .backslash_escape(true)
        .literal_separator(literal_separator);
    builder
        .build()
        .map(|glob| CompiledGlobMatcher {
            pattern: pattern.to_string(),
            matcher: glob.compile_matcher(),
        })
        .map_err(|err| anyhow!("invalid glob pattern {pattern:?}: {err}"))
}

fn normalize_hook_host(host: &str) -> Result<String> {
    let normalized = normalize_host(host);
    if normalized.is_empty() {
        return Err(anyhow!("host must not be empty"));
    }
    if normalized.contains('*') {
        return Err(anyhow!(
            "MITM hook hosts must be exact hosts and cannot contain wildcards"
        ));
    }
    Ok(normalized)
}

fn normalize_methods(methods: &[String]) -> Result<Vec<String>> {
    methods
        .iter()
        .map(|method| {
            let normalized = method.trim().to_ascii_uppercase();
            if normalized.is_empty() {
                return Err(anyhow!("methods must not contain empty entries"));
            }
            Ok(normalized)

View on GitHub (pinned to 339751715c)

Solutions

  1. Set host to an exact, bare hostname such as host = "api.example.com" — no scheme, path, or trailing slash
  2. Use the hook index in the 'invalid network.mitm_hooks[i].host' context to locate the offending entry
  3. Lint generated config for empty hosts before deploying

Example fix

# before — host omitted / empty
[[network.mitm_hooks]]
host = ""

# after
[[network.mitm_hooks]]
host = "api.example.com"
Defensive patterns

Strategy: validation

Validate before calling

// Rust — host must survive normalization non-empty
for (i, hook) in config.mitm_hooks.iter().enumerate() {
    if hook.host.trim().is_empty() {
        return Err(anyhow!("network.mitm_hooks[{i}].host is empty"));
    }
}

Type guard

fn hook_host_nonempty(hook: &MitmHookConfig) -> bool {
    !hook.host.trim().is_empty()
}

Try / catch

match validate_mitm_hook_config(&config) {
    Ok(()) => {}
    Err(err) => eprintln!("{err:#}"), // 'invalid network.mitm_hooks[i].host: host must not be empty'
}

Prevention

When it happens

Trigger: host key omitted (serde default is ""), host = "", or host = " " in a [[network.mitm_hooks]] entry; raised from both validate_mitm_hook_config and compile_mitm_hooks_with_resolvers.

Common situations: Writing only match/actions and forgetting host; placeholder not substituted by templating; whitespace introduced by generated config.

Related errors


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/d2da56650bacbd1d. Report an issue: GitHub.