hatoo/oha · error · anyhow::Error

Parse auth

Error message

Parse auth

What it means

When building the basic-auth header from --auth, run() splits the string with splitn(2, ':') and requires exactly two segments (username and password). An --auth value without any colon fails this ensure with the terse 'Parse auth' error while constructing request headers.

Solutions

  1. Provide --auth as `username:password`, always including the colon.
  2. For an empty password use a trailing colon, e.g. `--auth alice:` (the code accepts empty passwords).
  3. Check shell quoting so the full colon-containing string reaches oha.

Example fix

// before
oha --auth alice https://example.com
// after
oha --auth alice:s3cret https://example.com
Defensive patterns

Strategy: validation

Validate before calling

fn valid_basic_auth(auth: &str) -> bool {
    auth.contains(':')
}

Type guard

fn split_basic_auth(auth: &str) -> Option<(&str, &str)> {
    auth.split_once(':')
}

Try / catch

match run(opts).await {
    Err(e) if e.to_string().contains("Parse auth") => {
        eprintln!("--auth must be username:password (colon required)");
    }
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: Passing `--auth` (or `--basic-auth`) a string containing no ':' when not using --aws-sigv4, e.g. `--auth alice` or an empty/whitespace value.

Common situations: Providing only the username and forgetting the password; accidentally quoting away the colon; confusing --auth semantics with other tools that take just a token.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of hatoo/oha@4efba2d113 (2026-09-09). Data as JSON: /api/errors/fbfc25039ef04164. Report an issue: GitHub.

Appendix: source

Thrown at src/main.rs:518

        if let Some(h) = opts.accept_header {
            headers.insert(http::header::ACCEPT, HeaderValue::from_bytes(h.as_bytes())?);
        }

        if let Some(h) = opts.content_type.or(form_content_type) {
            headers.insert(
                http::header::CONTENT_TYPE,
                HeaderValue::from_bytes(h.as_bytes())?,
            );
        }

        if let Some(h) = opts.host {
            headers.insert(http::header::HOST, HeaderValue::from_bytes(h.as_bytes())?);
        }

        if let Some(auth) = opts.basic_auth {
            let u_p = auth.splitn(2, ':').collect::<Vec<_>>();
            anyhow::ensure!(u_p.len() == 2, anyhow::anyhow!("Parse auth"));
            let mut header_value = b"Basic ".to_vec();
            {
                use std::io::Write;
                let username = u_p[0];
                let password = if u_p[1].is_empty() {
                    None
                } else {
                    Some(u_p[1])
                };
                let mut encoder = base64::write::EncoderWriter::new(
                    &mut header_value,
                    &base64::engine::general_purpose::STANDARD,
                );
                // The unwraps here are fine because Vec::write* is infallible.
                write!(encoder, "{username}:").unwrap();
                if let Some(password) = password {
                    write!(encoder, "{password}").unwrap();
                }

View on GitHub (pinned to 4efba2d113)