{"record":{"id":"4f0788f058a0e893","repo":"nautechsystems/nautilus_trader","slug":"filter-key-is-not-a-string-or-array","errorCode":null,"errorMessage":"filter {key:?} is not a string or array","messagePattern":"filter (.+?) is not a string or array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/common/instruments.rs","lineNumber":103,"sourceCode":"fn filter_values(\n    config: &BinanceInstrumentProviderConfig,\n    key: &str,\n) -> anyhow::Result<Option<AHashSet<String>>> {\n    let Some(value) = config.filters.get(key) else {\n        return Ok(None);\n    };\n\n    let values = match value {\n        serde_json::Value::String(value) => vec![value.as_str()],\n        serde_json::Value::Array(values) => values\n            .iter()\n            .map(|value| {\n                value\n                    .as_str()\n                    .ok_or_else(|| anyhow::anyhow!(\"filter {key:?} contains a non-string value\"))\n            })\n            .collect::<anyhow::Result<Vec<_>>>()?,\n        _ => anyhow::bail!(\"filter {key:?} is not a string or array\"),\n    };\n\n    Ok(Some(\n        values\n            .into_iter()\n            .map(|value| value.trim().to_ascii_uppercase())\n            .collect(),\n    ))\n}\n\nfn matches_filter(values: &Option<AHashSet<String>>, value: &str) -> bool {\n    values.as_ref().is_none_or(|values| contains(values, value))\n}\n\nfn contains(values: &AHashSet<String>, value: &str) -> bool {\n    values.contains(&value.to_ascii_uppercase())\n}\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/common/instruments.rs#L85-L121","documentation":"filter_values extracts string values for a named exchange instrument filter (e.g. PRICE_FILTER's quote assets, PERMISSIONS) from the exchangeInfo JSON. The JSON value must be either a string (single value) or an array of strings; any other JSON shape (number, object, bool, null) hits the catch-all bail. Sibling code produces the similar 'contains a non-string value' error for arrays holding non-strings.","triggerScenarios":"Parsing a Binance exchangeInfo filter where the value at `key` is neither a string nor an array of strings — e.g. an API change emitting an object or number for a filter field, or fetching exchangeInfo from an unexpected endpoint/version (testnet, futures vs spot, a proxy returning an error JSON).","commonSituations":"Binance API/schema changes renaming or restructuring a filter field; pointing the instruments loader at the wrong market type so the response has a different schema; a cached or mocked exchangeInfo fixture with hand-written shapes.","solutions":["Verify you are fetching the correct exchangeInfo for your market type (spot vs futures vs testnet URLs) so the filter schema matches.","Update the adapter if Binance changed the filter field's shape — add handling for the new JSON type.","Log the raw filter JSON for the offending key to confirm the actual shape before parsing.","If using fixtures/mocks, regenerate them from a live exchangeInfo response."],"exampleFix":"// before\n_ => anyhow::bail!(\"filter {key:?} is not a string or array\"),\n// after\n_ => {\n    log::warn!(\"unexpected shape for filter {key:?}: {value:?}; skipping\");\n    return Ok(None); // degrade gracefully instead of failing instrument loading\n}","handlingStrategy":"type-guard","validationCode":"fn is_string_or_string_array(v: &serde_json::Value) -> bool {\n    v.is_string() || v.as_array().map_or(false, |a| a.iter().all(|e| e.is_string()))\n}","typeGuard":"fn filter_value_shape(value: &serde_json::Value) -> Option<Vec<String>> {\n    match value {\n        serde_json::Value::String(s) => Some(vec![s.clone()]),\n        serde_json::Value::Array(a) if a.iter().all(|e| e.is_string()) =>\n            Some(a.iter().filter_map(|e| e.as_str().map(String::from)).collect()),\n        _ => None,\n    }\n}","tryCatchPattern":"match parse_exchange_info(&body) {\n    Err(e) if e.to_string().contains(\"is not a string or array\") => {\n        log::error!(\"exchangeInfo schema changed or wrong endpoint; inspect raw filter JSON\");\n        Err(e.into())\n    }\n    other => other,\n}","preventionTips":["Fetch exchangeInfo from the endpoint matching your market type (spot vs futures vs testnet).","Log the raw JSON of unexpected filter shapes to detect API schema changes early.","Keep exchangeInfo fixtures regenerated from live responses rather than hand-written."],"tags":["binance","exchange-info","json-parsing","instrument-filters","rust"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}