{"record":{"id":"91a658cd6d2ffeab","repo":"nautechsystems/nautilus_trader","slug":"failed-to-serialize-json-e","errorCode":null,"errorMessage":"Failed to serialize JSON: {e}","messagePattern":"Failed to serialize JSON: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1728,"sourceCode":"                   WHERE (data_type = $1 OR data_type = $2)\n                     AND metadata = $3\n                     AND identifier = ''\n                   ORDER BY ts_init ASC\"#,\n                )\n                .bind(type_name)\n                .bind(short_type)\n                .bind(&metadata_json)\n                .fetch_all(pool)\n                .await\n            }\n        }\n        .map_err(|e| anyhow::anyhow!(\"Failed to load custom data: {e}\"))?;\n\n        let mut results = Vec::with_capacity(rows.len());\n        for row in rows {\n            let value_json: serde_json::Value = row.try_get(\"value\")?;\n            let json_bytes = serde_json::to_vec(&value_json)\n                .map_err(|e| anyhow::anyhow!(\"Failed to serialize JSON: {e}\"))?;\n            let custom =\n                CustomData::from_json_bytes(&json_bytes).map_err(|e| anyhow::anyhow!(\"{e}\"))?;\n            results.push(custom);\n        }\n        Ok(results)\n    }\n}\n","sourceCodeStart":1710,"sourceCodeEnd":1736,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1710-L1736","documentation":"Raised inside `load_custom_data`'s row loop when `serde_json::to_vec(&value_json)` fails to re-serialize the JSONB `value` column read from the database. Since the value came from serde_json::Value, this is rare but indicates the row's JSONB content cannot be converted back to bytes (or an internal conversion error).","triggerScenarios":"Iterating rows returned by load_custom_data where a row's `value` JSONB cannot be serialized to bytes — practically only with unusual JSONB values or an internal bug in the try_get/conversion path.","commonSituations":"Rows written by other tools with exotic JSONB content; type confusion between the sqlx JSONB decoding and serde_json::Value; corrupted rows.","solutions":["Inspect the `{e}` message for the serialization failure detail.","Re-read the offending row and inspect its `value` JSONB with psql.","Re-insert the affected row from a known-good source.","Upgrade the library/serde_json in case of a decoding bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let bytes = serde_json::to_vec(&value_json)\n    .map_err(|e| anyhow::anyhow!(\"row value not serializable: {e}\"))?;","preventionTips":["Only write rows through the library API to avoid exotic JSONB","Inspect suspicious rows with psql before retrying","Pin serde_json versions across the workspace"],"tags":["serde","json","serialization"],"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"}