nautechsystems/nautilus_trader · error · anyhow::Error

Gamma {scope} filter '{key}' must be an unsigned integer: {e

Error message

Gamma {scope} filter '{key}' must be an unsigned integer: {e}

What it means

parse_gamma_filter_u32 parses a string filter value as u32 for Gamma market/event filters. When value.parse::<u32>() fails (empty string, negative number, float, non-numeric, or value > u32::MAX), it wraps the parse error into 'Gamma {scope} filter {key} must be an unsigned integer'.

Source

Thrown at crates/adapters/polymarket/src/providers.rs:981

    set_u64!(parent_event_id);

    params.validate_keyset().map_err(anyhow::Error::msg)?;
    Ok(params)
}

fn parse_gamma_filter_bool(scope: &str, key: &str, value: &str) -> anyhow::Result<bool> {
    if value.eq_ignore_ascii_case("true") {
        Ok(true)
    } else if value.eq_ignore_ascii_case("false") {
        Ok(false)
    } else {
        anyhow::bail!("Gamma {scope} filter '{key}' must be true or false, was '{value}'")
    }
}

fn parse_gamma_filter_u32(scope: &str, key: &str, value: &str) -> anyhow::Result<u32> {
    value.parse::<u32>().map_err(|e| {
        anyhow::anyhow!("Gamma {scope} filter '{key}' must be an unsigned integer: {e}")
    })
}

fn parse_gamma_filter_u64(scope: &str, key: &str, value: &str) -> anyhow::Result<u64> {
    value.parse::<u64>().map_err(|e| {
        anyhow::anyhow!("Gamma {scope} filter '{key}' must be an unsigned integer: {e}")
    })
}

fn parse_gamma_filter_decimal(scope: &str, key: &str, value: &str) -> anyhow::Result<Decimal> {
    parse_decimal_exact(value)
        .map_err(|e| anyhow::anyhow!("Gamma {scope} filter '{key}' must be a decimal number: {e}"))
}

fn parse_gamma_filter_list(scope: &str, key: &str, value: &str) -> anyhow::Result<Vec<String>> {
    let values = value
        .split(',')
        .map(str::trim)

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set the filter value to a plain non-negative integer string, e.g. "50"
  2. Strip whitespace, thousands separators, and quotes from the config value before passing it
  3. Clamp or round user input to an integer in the calling layer before building params
  4. If a value near 4 billion is needed, confirm it fits u32; otherwise check for the u64 variant

Example fix

// before
params.max_markets = Some("1.5".to_string());
// after
params.max_markets = Some("2".to_string());
Defensive patterns

Strategy: validation

Validate before calling

// Rust
fn is_u32_filter(v: &str) -> bool { v.trim().parse::<u32>().is_ok() }
assert!(is_u32_filter("50"));
assert!(!is_u32_filter("1.5"));

Prevention

When it happens

Trigger: Supplying a market or event filter (scope='market' or 'event') whose value cannot parse as u32, e.g. max_markets="all", max_markets="-1", or max_markets="1.5" in the filter hashmap.

Common situations: Typos in config files ("3,000" with comma), shell quoting producing empty strings, users entering floats or signed numbers for count-like filters.

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 nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/f9b5697cb87995b3. Report an issue: GitHub.