nautechsystems/nautilus_trader · error · anyhow::Error

params.validate_keyset().map_err(|e| anyhow::anyhow!(e))?;

Error message

params.validate_keyset().map_err(|e| anyhow::anyhow!(e))?;

What it means

build_gamma_params_from_hashmap converts string key/value filter maps into GammaMarketParams and then calls params.validate_keyset(). This error surfaces when the assembled keyset fails the params struct's own validation, e.g. required pagination keys are absent or the keyset combination is inconsistent for Gamma market queries. The underlying keyset error is wrapped into an anyhow::Error and propagated to every Gamma query path (fetch_bulk_instruments, query_markets, config loading, provider validation).

Source

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

    if let Some(v) = map.get("sports_market_types") {
        params.sports_market_types =
            Some(parse_gamma_filter_list("market", "sports_market_types", v)?);
    }

    if let Some(v) = map.get("include_tag") {
        params.include_tag = Some(parse_gamma_filter_bool("market", "include_tag", v)?);
    }

    if let Some(v) = map.get("locale") {
        params.locale = Some(parse_gamma_filter_string("market", "locale", v)?);
    }

    if let Some(v) = map.get("max_markets") {
        params.max_markets = Some(parse_gamma_filter_u32("market", "max_markets", v)?);
    }

    params.validate_keyset().map_err(|e| anyhow::anyhow!(e))?;
    Ok(params)
}

/// Builds validated event keyset parameters from string key/value filters.
///
/// # Errors
///
/// Returns an error for unknown keys, malformed values, or invalid filter combinations.
pub fn build_gamma_event_params_from_hashmap(
    map: &HashMap<String, String>,
) -> anyhow::Result<GetGammaEventsParams> {
    for key in map.keys() {
        match key.as_str() {
            "is_active" | "active" | "closed" | "archived" | "id" | "slug" | "live"
            | "featured" | "cyom" | "title_search" | "liquidity_min" | "liquidity_max"
            | "volume_min" | "volume_max" | "start_date_min" | "start_date_max"
            | "end_date_min" | "end_date_max" | "start_time_min" | "start_time_max" | "tag_id"
            | "tag_slug" | "exclude_tag_id" | "related_tags" | "tag_match" | "series_id"

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the inner validate_keyset() error message (it is preserved by anyhow::anyhow!(e)) to see which keyset rule failed
  2. Check the filter map keys for missing or mutually conflicting entries required by GammaMarketParams::validate_keyset
  3. Fix the config/source producing the filter map so the parsed params satisfy the keyset rules
  4. If constructing params programmatically, call validate_keyset() yourself right after building to fail early with a clearer stack

Example fix

// before
let params = build_gamma_params_from_hashmap(map)?;
// after
let params = build_gamma_params_from_hashmap(map)
    .map_err(|e| { eprintln!("invalid gamma filter set: {e:#}"); e })?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: validate the filter map before calling the provider
fn validate_gamma_filters(map: &HashMap<String, String>) -> Result<(), String> {
    // mirror required/conflicting keys checked by GammaMarketParams::validate_keyset
    for (k, v) in map {
        if v.trim().is_empty() { return Err(format!("filter '{k}' is empty")); }
    }
    Ok(())
}

Prevention

When it happens

Trigger: Calling any Gamma market query with a filter map whose parsed values fail validate_keyset() on GammaMarketParams — e.g. providing filter combinations that violate the keyset rules enforced by that method.

Common situations: Passing contradictory or incomplete market filter maps (e.g. via config files or Python bindings through py_new) so that the resulting params struct is invalid after parsing; also hit during validate_provider_config when startup config produces invalid keysets.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/943b0015f4afd837. Report an issue: GitHub.