{"record":{"id":"40e60ebc4153b902","repo":"nautechsystems/nautilus_trader","slug":"invalid-okx-websocket-channel","errorCode":null,"errorMessage":"Invalid OKX websocket channel","messagePattern":"Invalid OKX websocket channel","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/adapters/okx/src/websocket/handler.rs","lineNumber":636,"sourceCode":"                            arg,\n                            conn_id,\n                            ..\n                        } => {\n                            let channel_str = serde_json::to_string(&arg.channel)\n                                .expect(\"Invalid OKX websocket channel\")\n                                .trim_matches('\"')\n                                .to_string();\n                            log::debug!(\"{event}d: channel={channel_str}, conn_id={conn_id}\");\n                            Some(ws_event)\n                        }\n                        OKXWsFrame::ChannelConnCount {\n                            channel,\n                            conn_count,\n                            conn_id,\n                            ..\n                        } => {\n                            let channel_str = serde_json::to_string(channel)\n                                .expect(\"Invalid OKX websocket channel\")\n                                .trim_matches('\"')\n                                .to_string();\n                            log::debug!(\n                                \"Channel connection status: \\\n                                 channel={channel_str}, connections={conn_count}, conn_id={conn_id}\",\n                            );\n                            None\n                        }\n                        OKXWsFrame::Ping => {\n                            log::trace!(\"Ignoring ping event parsed from text payload\");\n                            None\n                        }\n                        OKXWsFrame::Data { .. }\n                        | OKXWsFrame::BookData { .. }\n                        | OKXWsFrame::RpiBookData { .. } => Some(ws_event),\n                        OKXWsFrame::OrderResponse {\n                            id, op, code, data, ..\n                        } => {","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/websocket/handler.rs#L618-L654","documentation":"The OKX websocket handler deserializes a parsed channel enum back to a JSON string with serde_json::to_string when logging connection-status events. The expect panics if serializing the channel value fails, which should be impossible for an enum that was just parsed from JSON; it is an internal invariant assertion labeled 'Invalid OKX websocket channel'.","triggerScenarios":"Receiving a websocket 'channel-conn-count' style event whose channel variant fails JSON serialization in parse_raw_message; practically only reachable if the channel enum's Serialize impl is broken or a non-serializable representation is produced upstream.","commonSituations":"OKX changing event payload shapes after an adapter update; locally patched enum variants that don't round-trip; corrupted or malformed frames from proxies.","solutions":["Update the nautilus OKX adapter to match the current OKX websocket API event schema.","Log the channel with Debug (`{:?}`) instead of re-serializing to JSON if you patch locally.","Report the raw payload if it persists, since this path is an internal invariant and should not panic."],"exampleFix":"// before\nlet channel_str = serde_json::to_string(channel)\n    .expect(\"Invalid OKX websocket channel\")\n    .trim_matches('\"')\n    .to_string();\n\n// after\nlet channel_str = format!(\"{:?}\", channel); // cannot panic","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// treat as an internal invariant: catch at the ws message loop boundary\nmatch std::panic::catch_unwind(|| handler.parse_raw_message(raw.clone())) {\n    Ok(v) => v,\n    Err(_) => { log::error!(\"unparseable OKX channel event: {raw}\"); continue; }\n}","preventionTips":["Keep the OKX adapter updated with the venue's current websocket event schema.","Log raw payloads before parsing so malformed frames are diagnosable.","Avoid patching channel enums locally without ensuring they round-trip Serialize."],"tags":["rust","websocket","okx","serialization","panic"],"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"}