ducaale/xh · error

is not a valid value

Error message

{:?} is not a valid value

What it means

The -p/--print value parser accepts only the characters H, B, h, b, m (request headers/body, response headers/body/meta). Any other character in the print specifier returns this anyhow error naming the offending char.

Solutions

  1. Use only the letters H B h b m in the print specifier (e.g. -p hb for response body+headers)
  2. Remove invalid characters from the -p argument
  3. Check `http --help` for the documented print spec characters

Example fix

# before
http -p Hx GET example.org
# after
http -p hB GET example.org
Defensive patterns

Strategy: validation

Validate before calling

// validate the print spec before invoking
fn valid_print(spec: &str) -> bool {
    !spec.is_empty() && spec.chars().all(|c| matches!(c, 'H'|'B'|'h'|'b'|'m'))
}
assert!(valid_print(&print_spec));

Type guard

fn is_print_spec(s: &str) -> bool { s.chars().all(|c| "HBhbm".contains(c)) && !s.is_empty() }

Try / catch

let out = Command::new("http").args(["-p", &print_spec, "GET", url]).output()?;
if !out.status.success() && String::from_utf8_lossy(&out.stderr).contains("is not a valid value") {
    eprintln!("invalid -p spec '{print_spec}': use only H B h b m");
}

Prevention

When it happens

Trigger: Passing -p or --print with a character outside {H,B,h,b,m}, e.g. -pHx or -phdr.

Common situations: Typos in the print spec; confusion with curl-style flags; scripts copying print strings between tools.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/cli.rs:1173

}

impl FromStr for Print {
    type Err = anyhow::Error;
    fn from_str(s: &str) -> anyhow::Result<Print> {
        let mut request_headers = false;
        let mut request_body = false;
        let mut response_headers = false;
        let mut response_body = false;
        let mut response_meta = false;

        for char in s.chars() {
            match char {
                'H' => request_headers = true,
                'B' => request_body = true,
                'h' => response_headers = true,
                'b' => response_body = true,
                'm' => response_meta = true,
                char => return Err(anyhow!("{:?} is not a valid value", char)),
            }
        }

        let p = Print {
            request_headers,
            request_body,
            response_headers,
            response_body,
            response_meta,
        };
        Ok(p)
    }
}

#[derive(Debug, Clone)]
pub struct Timeout(Duration);

impl Timeout {

View on GitHub (pinned to 2404aceecc)