{"record":{"id":"9f2e582051206e00","repo":"nautechsystems/nautilus_trader","slug":"failed-to-serialize-config-value-e-9f2e58","errorCode":null,"errorMessage":"Failed to serialize config value: {e}","messagePattern":"Failed to serialize config value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/python/node.rs","lineNumber":598,"sourceCode":") -> anyhow::Result<Bound<'py, PyAny>> {\n    if key == \"actor_id\"\n        && let Some(actor_id) = value.as_str()\n    {\n        return Ok(ActorId::new_checked(actor_id)?\n            .into_pyobject(py)?\n            .into_any());\n    }\n\n    if key == \"strategy_id\"\n        && let Some(strategy_id) = value.as_str()\n    {\n        return Ok(StrategyId::new_checked(strategy_id)?\n            .into_pyobject(py)?\n            .into_any());\n    }\n\n    let json_str = serde_json::to_string(value)\n        .map_err(|e| anyhow::anyhow!(\"Failed to serialize config value: {e}\"))?;\n    Ok(PyModule::import(py, \"json\")?\n        .call_method(\"loads\", (json_str,), None)?\n        .into_any())\n}\n","sourceCodeStart":580,"sourceCodeEnd":603,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/python/node.rs#L580-L603","documentation":"Raised by `config_value_to_py` when a single config value cannot be serialized to JSON with `serde_json::to_string` as part of converting the Rust config map into a Python dict. Values like StrategyId are handled specially; anything else goes through serde_json, which fails for non-serializable types (e.g. maps with non-string keys, arbitrary Rust types without Serialize).","triggerScenarios":"Passing a config entry whose value cannot be JSON-serialized: a HashMap/BTreeMap with non-string keys (serde_json requires string keys for maps), a float that is NaN/Infinity (serde_json rejects them by default), or a custom type not implementing serde::Serialize in a way JSON supports.","commonSituations":"Users constructing a backtest node config programmatically in Rust with nested maps keyed by integers/enums; NaN appearing from computed default values; custom config structs with unsupported field types (e.g. tuple keys, non-string enum keys).","solutions":["Convert non-string map keys to Strings before putting them in the config","Sanitize floats: replace NaN/Infinity with valid values or omit the entry","Use only JSON-compatible types (string, bool, i64/u64, f64 finite, Vec, String-keyed map) for config values","If it is a custom type, implement Serialize/Deserialize for it in a JSON-compatible form"],"exampleFix":"// before\nlet config: HashMap<String, ConfigValue> = ...; config.insert(\"ratios\".into(), map keyed by u32)\n// after\nlet string_keyed: BTreeMap<String, f64> = inner.into_iter().map(|(k, v)| (k.to_string(), v)).collect();","handlingStrategy":"validation","validationCode":"// Pre-validate config values are JSON-serializable\nserde_json::to_string(&value).map_err(|e| format!(\"config value '{key}' not serializable: {e}\"))?;","typeGuard":"fn is_json_serializable(v: &ConfigValue) -> bool { serde_json::to_string(v).is_ok() }","tryCatchPattern":"match create_importable_component(...) {\n    Err(e) if e.to_string().contains(\"Failed to serialize config value\") => {\n        eprintln!(\"non-JSON config value: {e:#}\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Use only JSON-compatible types in config maps (string keys, finite floats)","Check for NaN/Infinity in computed defaults before inserting into config","Add a debug serialization pass over config before launching the node"],"tags":["serde","serialization","config","rust"],"backgroundTag":"json-marshal-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}