{"record":{"id":"943b0015f4afd837","repo":"nautechsystems/nautilus_trader","slug":"params-validate-keyset-map-err-e-anyhow-anyho","errorCode":null,"errorMessage":"params.validate_keyset().map_err(|e| anyhow::anyhow!(e))?;","messagePattern":"params\\.validate_keyset\\(\\)\\.map_err\\(\\|e\\| anyhow::anyhow!\\(e\\)\\)\\?;","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/providers.rs","lineNumber":819,"sourceCode":"\n    if let Some(v) = map.get(\"sports_market_types\") {\n        params.sports_market_types =\n            Some(parse_gamma_filter_list(\"market\", \"sports_market_types\", v)?);\n    }\n\n    if let Some(v) = map.get(\"include_tag\") {\n        params.include_tag = Some(parse_gamma_filter_bool(\"market\", \"include_tag\", v)?);\n    }\n\n    if let Some(v) = map.get(\"locale\") {\n        params.locale = Some(parse_gamma_filter_string(\"market\", \"locale\", v)?);\n    }\n\n    if let Some(v) = map.get(\"max_markets\") {\n        params.max_markets = Some(parse_gamma_filter_u32(\"market\", \"max_markets\", v)?);\n    }\n\n    params.validate_keyset().map_err(|e| anyhow::anyhow!(e))?;\n    Ok(params)\n}\n\n/// Builds validated event keyset parameters from string key/value filters.\n///\n/// # Errors\n///\n/// Returns an error for unknown keys, malformed values, or invalid filter combinations.\npub fn build_gamma_event_params_from_hashmap(\n    map: &HashMap<String, String>,\n) -> anyhow::Result<GetGammaEventsParams> {\n    for key in map.keys() {\n        match key.as_str() {\n            \"is_active\" | \"active\" | \"closed\" | \"archived\" | \"id\" | \"slug\" | \"live\"\n            | \"featured\" | \"cyom\" | \"title_search\" | \"liquidity_min\" | \"liquidity_max\"\n            | \"volume_min\" | \"volume_max\" | \"start_date_min\" | \"start_date_max\"\n            | \"end_date_min\" | \"end_date_max\" | \"start_time_min\" | \"start_time_max\" | \"tag_id\"\n            | \"tag_slug\" | \"exclude_tag_id\" | \"related_tags\" | \"tag_match\" | \"series_id\"","sourceCodeStart":801,"sourceCodeEnd":837,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/providers.rs#L801-L837","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the inner validate_keyset() error message (it is preserved by anyhow::anyhow!(e)) to see which keyset rule failed","Check the filter map keys for missing or mutually conflicting entries required by GammaMarketParams::validate_keyset","Fix the config/source producing the filter map so the parsed params satisfy the keyset rules","If constructing params programmatically, call validate_keyset() yourself right after building to fail early with a clearer stack"],"exampleFix":"// before\nlet params = build_gamma_params_from_hashmap(map)?;\n// after\nlet params = build_gamma_params_from_hashmap(map)\n    .map_err(|e| { eprintln!(\"invalid gamma filter set: {e:#}\"); e })?;","handlingStrategy":"validation","validationCode":"// Rust: validate the filter map before calling the provider\nfn validate_gamma_filters(map: &HashMap<String, String>) -> Result<(), String> {\n    // mirror required/conflicting keys checked by GammaMarketParams::validate_keyset\n    for (k, v) in map {\n        if v.trim().is_empty() { return Err(format!(\"filter '{k}' is empty\")); }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build GammaMarketParams early and call validate_keyset() immediately after construction","Centralize filter-map construction in one function so keyset rules are enforced in one place","Include the inner error chain ({e:#}) in logs to reveal the exact keyset rule violated"],"tags":["validation","config","polymarket","gamma-api"],"backgroundTag":"invalid-config-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}