ducaale/xh · error

Unknown auth type

Error message

Unknown auth type {}

What it means

Match fallthrough in session's auth parsing: the session file's 'auth' object carries an authType that is not one of the recognized schemes ('basic', 'digest', ...), so no arm matches and the value is rejected as an unknown authentication type. This is a generic sentinel guard against corrupted or hand-edited session files containing an unsupported auth_type/raw_auth pair.

Solutions

  1. Use one of the supported values: basic, digest, or bearer
  2. Fix the typo in --auth-type (e.g. 'Bearer' -> 'bearer'; it is lowercase)
  3. Edit or delete the offending session file (~/.cache/xh/<host>_<port>) if its authType is invalid
  4. If the scheme is not supported, pre-generate the header yourself and pass it via -A/--auth with basic or Authorization header

Example fix

// before
xh --auth-type=oauth user:pass GET https://api.example.com
// after
xh --auth-type=bearer --auth=eyJhbGciOi... GET https://api.example.com
Defensive patterns

Strategy: validation

Validate before calling

const VALID: [&str; 3] = ["basic", "digest", "bearer"];
if let Some(t) = auth_type {
    if !VALID.contains(&t.as_str()) {
        eprintln!("auth-type must be one of basic|digest|bearer");
        std::process::exit(2);
    }
}

Type guard

fn is_valid_auth_type(s: &str) -> bool {
    matches!(s, "basic" | "digest" | "bearer")
}

Try / catch

match result {
    Err(e) if e.to_string().starts_with("Unknown auth type") => {
        eprintln!("use --auth-type=basic|digest|bearer");
    }
    r => r?,
}

Prevention

When it happens

Trigger: Running `xh --auth-type=<anything-other-than-basic|digest|bearer> ...`, or loading a saved session file whose authType field contains an unrecognized value, or a typo like 'token', 'jwt', 'oauth'.

Common situations: Typo in --auth-type; copying flags from other HTTP clients (curl/HTTPie use different names); stale session JSON written by a newer/older xh version with different enum values.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of ducaale/xh@2404aceecc (2026-09-13). Data as JSON: /api/errors/adb343a9549117c4. Report an issue: GitHub.

Appendix: source

Thrown at src/session.rs:248

        if let Auth {
            auth_type: Some(auth_type),
            raw_auth: Some(raw_auth),
        } = &self.content.auth
        {
            match auth_type.as_str() {
                "basic" => {
                    let (username, password) = auth::parse_auth(raw_auth, "")?;
                    Ok(Some(auth::Auth::Basic(username, password)))
                }
                "digest" => {
                    let (username, password) = auth::parse_auth(raw_auth, "")?;
                    Ok(Some(auth::Auth::Digest(
                        username,
                        password.unwrap_or_default(),
                    )))
                }
                "bearer" => Ok(Some(auth::Auth::Bearer(raw_auth.into()))),
                _ => Err(anyhow!("Unknown auth type {}", raw_auth)),
            }
        } else {
            Ok(None)
        }
    }

    pub fn save_auth(&mut self, auth: &auth::Auth) {
        match auth {
            auth::Auth::Basic(username, password) => {
                let password = password.as_deref().unwrap_or("");
                self.content.auth = Auth {
                    auth_type: Some("basic".into()),
                    raw_auth: Some(format!("{username}:{password}")),
                }
            }
            auth::Auth::Digest(username, password) => {
                self.content.auth = Auth {
                    auth_type: Some("digest".into()),

View on GitHub (pinned to 2404aceecc)