ducaale/xh · error

Unknown option

Error message

Unknown option '{key}'

What it means

The --format-options parser hit a key it does not recognize at all (not even as an explicitly unsupported one), producing 'Unknown option'. The parser whitelists known dotted keys like xml.indent, xml.format, etc.

Solutions

  1. Check the supported --format-options keys for this version (e.g. json.format, json.indent, xml.format, xml.indent, headers.sort, etc.)
  2. Fix typos in the option key
  3. Consult --help or the README for the exact option names

Example fix

# before
http --format-options=xml.indnt=4 GET example.org
# after
http --format-options=xml.indent=4 GET example.org
Defensive patterns

Strategy: validation

Validate before calling

// validate keys against the whitelist before running
const KNOWN: &[&str] = &["json.format","json.indent","xml.format","xml.indent","headers.sort","headers.warn"];
let key = kv.split('=').next().unwrap();
if !KNOWN.contains(&key) { eprintln!("unknown format option: {key}"); }

Try / catch

let out = Command::new("http").args([&format!("--format-options={opt}"), ...]).output()?;
if !out.status.success() && String::from_utf8_lossy(&out.stderr).contains("Unknown option") {
    eprintln!("bad --format-options key in '{opt}'; see http --help");
}

Prevention

When it happens

Trigger: Passing --format-options=<unrecognized-key>=<value> with a key outside the parser's match arms.

Common situations: Typo in an option key (e.g. 'xml.indnt'); using options from a different tool version or another HTTP client; guessing option names.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/cli.rs:1046

                    format_options.json_indent = Some(value.parse().with_context(value_error)?);
                }
                "json.format" => {
                    format_options.json_format = Some(value.parse().with_context(value_error)?);
                }
                "headers.sort" => {
                    format_options.headers_sort = Some(value.parse().with_context(value_error)?);
                }
                "xml.indent" => {
                    format_options.xml_indent = Some(value.parse().with_context(value_error)?);
                }
                "xml.format" => {
                    format_options.xml_format = Some(value.parse().with_context(value_error)?);
                }
                "json.sort_keys" => {
                    return Err(anyhow!("Unsupported option '{key}'"));
                }
                _ => {
                    return Err(anyhow!("Unknown option '{key}'"));
                }
            }
        }
        Ok(format_options)
    }
}

#[derive(Default, ValueEnum, Debug, PartialEq, Eq, Clone, Copy)]
pub enum Theme {
    #[default]
    Auto,
    Solarized,
    Monokai,
    Fruity,
}

impl Theme {
    pub fn as_str(&self) -> &'static str {

View on GitHub (pinned to 2404aceecc)