Hmbown/CodeWhale · error

header name cannot be empty

Error message

header name cannot be empty

What it means

parse_http_headers parses header pairs in the form name=value (e.g. from provider header config) and inserts them into a map. The library throws this error when the part before the '=' is empty after trimming, because an HTTP header name is required to carry the value. It is an input-validation guard, not a runtime fault.

Solutions

  1. Add a non-empty header name before the '=' in the offending pair
  2. Remove stray/empty separators so every segment has the form name=value
  3. Trim whitespace-only names — whitespace alone is also rejected

Example fix

// before
headers = "=Bearer abc123"
// after
headers = "Authorization=Bearer abc123"
Defensive patterns

Strategy: validation

Validate before calling

fn valid_header_pair(pair: &str) -> bool {
    pair.split_once('=')
        .map(|(n, _)| !n.trim().is_empty())
        .unwrap_or(false)
}

Type guard

fn is_header_pair(s: &str) -> Option<(&str, &str)> {
    s.split_once('=')
        .filter(|(n, _)| !n.trim().is_empty())
}

Try / catch

match parse_http_headers(&raw) {
    Ok(headers) => headers,
    Err(e) if e.to_string().contains("header name cannot be empty") => {
        eprintln!("fix the header pair: {e}");
        Default::default()
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling any config API that routes through parse_http_headers with a pair like '=value', ' =value', or a trailing separator such as 'A=1;' where the empty segment's name is empty.

Common situations: Copy-pasting a header list from curl docs with stray separators, editing provider custom-header entries in config.toml and accidentally deleting the name, or building the header string programmatically by joining with '=' and including empty entries.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/config/src/lib.rs:6579

        "0" | "false" | "no" | "off" | "disabled" => Ok(false),
        _ => bail!("invalid boolean '{raw}'"),
    }
}

fn parse_http_headers(raw: &str) -> Result<BTreeMap<String, String>> {
    let mut headers = BTreeMap::new();
    for pair in raw.trim().split(',') {
        let pair = pair.trim();
        if pair.is_empty() {
            continue;
        }
        let Some((name, value)) = pair.split_once('=') else {
            bail!("invalid header pair '{pair}', expected name=value");
        };
        let name = name.trim();
        let value = value.trim();
        if name.is_empty() {
            bail!("header name cannot be empty");
        }
        if value.is_empty() {
            continue;
        }
        headers.insert(name.to_string(), value.to_string());
    }
    Ok(headers)
}

fn serialize_http_headers(headers: &BTreeMap<String, String>) -> Option<String> {
    if headers.is_empty() {
        return None;
    }
    Some(
        headers
            .iter()
            .map(|(name, value)| format!("{name}={value}"))
            .collect::<Vec<_>>()

View on GitHub (pinned to 73e0f67d83)