{"record":{"id":"dffa2fcad0ec439b","repo":"nautechsystems/nautilus_trader","slug":"serialize-ws-order-request-e","errorCode":null,"errorMessage":"serialize WS order request: {e}","messagePattern":"serialize WS order request: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/kraken/src/websocket/dispatch/spot_orders.rs","lineNumber":257,"sourceCode":"            },\n            identity,\n            ts_now_ns,\n        )\n    }\n\n    fn send(\n        self: &Arc<Self>,\n        mut envelope: KrakenWsRequest,\n        mut identity: PendingRequest,\n        ts_now_ns: u64,\n    ) -> anyhow::Result<u64> {\n        let req_id = self.next_req_id();\n        envelope.req_id = Some(req_id);\n        identity.ts_sent_ns = ts_now_ns;\n\n        let payload = SecretString::from(\n            serde_json::to_string(&envelope)\n                .map_err(|e| anyhow::anyhow!(\"serialize WS order request: {e}\"))?,\n        );\n\n        let cmd_tx = self\n            .cmd_tx()\n            .ok_or_else(|| anyhow::anyhow!(\"WS handler command sender unavailable\"))?;\n\n        self.pending.insert(req_id, identity);\n\n        if let Err(e) = cmd_tx.send(SpotHandlerCommand::SendOrderRequest { req_id, payload }) {\n            self.pending.remove(&req_id);\n            anyhow::bail!(\"handler command channel closed: {e}\");\n        }\n\n        let state_for_timeout = Arc::downgrade(self);\n        let task_spawner = self.task_spawner.read().clone();\n        let cancel = task_spawner.cancellation_token();\n        let timeout = self.timeout;\n","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/kraken/src/websocket/dispatch/spot_orders.rs#L239-L275","documentation":"The Kraken spot WebSocket adapter failed to serialize the outgoing order request envelope into JSON before sending it to the WS handler. serde_json cannot convert the envelope struct to a string (e.g. a serialization error in a field type), so the adapter bails with an anyhow error wrapping the serde message. This prevents the order from ever reaching Kraken, and it is raised before the request is queued in `pending`.","triggerScenarios":"Calling `send` on the Kraken spot orders WS dispatcher when `serde_json::to_string(&envelope)` returns an Err — i.e. the constructed order envelope contains data serde cannot serialize (typically a non-string-key map, NaN/Infinity-style value, or a custom Serialize impl returning an error).","commonSituations":"Constructing an order request with an unexpected field type after an adapter upgrade; custom or modified envelope structs whose Serialize impl fails; rarely, corrupted order parameters flowing into the envelope.","solutions":["Check the wrapped serde error message (`{e}`) in the log to identify the exact field that failed to serialize.","Verify the order parameters passed into `send` (price, quantity, type fields) are valid domain values before the envelope is built.","Ensure you are on a consistent adapter version where the envelope struct and its field types match; upgrade/patch if a serialization bug exists.","If you maintain the adapter, ensure no field in the envelope has a Serialize impl that can fail (use plain strings/numbers instead of maps with non-string keys)."],"exampleFix":"// before\nlet payload = SecretString::from(\n    serde_json::to_string(&envelope)\n        .map_err(|e| anyhow::anyhow!(\"serialize WS order request: {e}\"))?,\n);\n// after\n// Validate fields before serializing so serde can never fail:\nassert!(!envelope.order_payload.is_empty());\nlet payload = SecretString::from(\n    serde_json::to_string(&envelope)\n        .map_err(|e| anyhow::anyhow!(\"serialize WS order request: {e}\"))?,\n);","handlingStrategy":"try-catch","validationCode":"// Validate envelope fields before serializing\nassert!(!envelope.order_payload.is_empty(), \"order payload must not be empty\");","typeGuard":null,"tryCatchPattern":"match serde_json::to_string(&envelope) {\n    Ok(json) => SecretString::from(json),\n    Err(e) => { log::error!(\"WS order serialize failed: {e}\"); return; }\n}","preventionTips":["Log the full wrapped serde error to pinpoint the failing field.","Keep envelope field types simple (strings/numbers) with infallible Serialize impls.","Pin adapter versions to avoid envelope struct drift."],"tags":["websocket","serialization","order-request","kraken"],"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"}