ducaale/xh · error

Unsupported option

Error message

Unsupported option '{key}'

What it means

The --format-options parser explicitly rejects the key 'json.sort_keys' as unsupported, even though it follows the dotted key=value syntax. Any other unrecognized key yields the separate 'Unknown option' error.

Solutions

  1. Remove json.sort_keys from --format-options
  2. Request the feature upstream or patch cli.rs to implement sorted JSON keys
  3. Use a post-processing step (e.g. jq -S) to sort JSON output

Example fix

# before
http --format-options=json.sort_keys=true GET example.org
# after
http GET example.org | jq -S .
Defensive patterns

Strategy: validation

Validate before calling

// validate format options before invoking
const SUPPORTED: &[&str] = &["json.format","json.indent","xml.format","xml.indent","headers.sort"];
for kv in opts.split(',') {
    let key = kv.split('=').next().unwrap();
    if key == "json.sort_keys" { eprintln!("json.sort_keys is unsupported; pipe through jq -S instead"); }
}

Try / catch

let out = Command::new("http").args([&"--format-options=json.sort_keys=true", ...]).output()?;
if !out.status.success() && String::from_utf8_lossy(&out.stderr).contains("Unsupported option") {
    eprintln!("json.sort_keys unsupported; use: http ... | jq -S .");
}

Prevention

When it happens

Trigger: Passing --format-options=json.sort_keys=true (or any value) on the command line; the key is matched by an explicit arm that errors.

Common situations: Users assuming JSON output supports a sort_keys toggle similar to Python's json.dumps; copying format options from other HTTPie-like tools.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/cli.rs:1043

            match key {
                "json.indent" => {
                    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,
}

View on GitHub (pinned to 2404aceecc)