{"record":{"id":"b1e27a147a5f5ef7","repo":"nautechsystems/nautilus_trader","slug":"failed-to-serialize-subscription-e","errorCode":null,"errorMessage":"Failed to serialize subscription: {e}","messagePattern":"Failed to serialize subscription: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/websocket/handler.rs","lineNumber":538,"sourceCode":"        self.handle_subscription_ack(&event, arg, Some(code), Some(msg))\n    }\n\n    async fn handle_subscribe(&self, args: Vec<OKXSubscriptionArg>) -> anyhow::Result<()> {\n        for arg in &args {\n            log::debug!(\n                \"Subscribing to channel: channel={:?}, inst_id={:?}\",\n                arg.channel,\n                arg.inst_id\n            );\n        }\n\n        let message = OKXSubscription {\n            op: OKXWsOperation::Subscribe,\n            args,\n        };\n\n        let json_txt = serde_json::to_string(&message)\n            .map_err(|e| anyhow::anyhow!(\"Failed to serialize subscription: {e}\"))?;\n\n        self.send_with_retry(json_txt, Some(OKX_RATE_LIMIT_KEY_SUBSCRIPTION.as_slice()))\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to send subscription after retries: {e}\"))?;\n        Ok(())\n    }\n\n    async fn handle_unsubscribe(&self, args: Vec<OKXSubscriptionArg>) -> anyhow::Result<()> {\n        for arg in &args {\n            log::debug!(\n                \"Unsubscribing from channel: channel={:?}, inst_id={:?}\",\n                arg.channel,\n                arg.inst_id\n            );\n        }\n\n        let message = OKXSubscription {\n            op: OKXWsOperation::Unsubscribe,","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/websocket/handler.rs#L520-L556","documentation":"`handle_subscribe` serializes the OKXSubscription (op=subscribe with args) to JSON before sending. Serialization of these strongly-typed structs should never fail in practice; if it does (corrupt/invalid subscription args producing unserializable data), the error is surfaced wrapped in this message.","triggerScenarios":"`serde_json::to_string(&OKXSubscription{...})` returns Err while handling a subscribe command — e.g. arg values containing types that fail serialization.","commonSituations":"Extremely rare; usually indicates a bug in constructed subscription args (e.g. non-finite floats or invalid map keys in custom arg fields) rather than a user configuration issue.","solutions":["Inspect the inner `{e}` and the args being subscribed; fix the arg construction to use plain strings/numbers.","Validate subscription parameters (inst_id, channel, depth) are normal UTF-8 strings before subscribing.","Report as a bug if it occurs with standard subscription args; serde serialization of these structs is expected to always succeed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// rust\n// ensure args are plain strings before subscribing\nassert!(args.iter().all(|a| !a.inst_id.as_deref().unwrap_or(\"\").is_empty()));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build subscriptions only through the adapter's public subscribe API.","Use plain string/numeric values in subscription args.","Report persistent serialization failures as a library bug."],"tags":["websocket","okx","serialization","subscribe"],"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-14T05:17:10.506Z"}