{"record":{"id":"2c0e76adb908e276","repo":"nautechsystems/nautilus_trader","slug":"invalid-data-type-json-e","errorCode":null,"errorMessage":"Invalid data_type JSON: {e}","messagePattern":"Invalid data_type JSON: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/mod.rs","lineNumber":805,"sourceCode":"\n        if let Some(ref id) = self.identifier {\n            map.insert(\n                \"identifier\".to_string(),\n                serde_json::Value::String(id.clone()),\n            );\n        }\n        serde_json::to_string(&serde_json::Value::Object(map))\n    }\n\n    /// Deserializes from JSON produced by `to_persistence_json`.\n    /// Accepts legacy JSON with `topic` (ignored); topic is rebuilt from `type_name` + metadata.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the string is not valid JSON or missing required fields.\n    pub fn from_persistence_json(s: &str) -> Result<Self, anyhow::Error> {\n        let value: serde_json::Value =\n            serde_json::from_str(s).map_err(|e| anyhow::anyhow!(\"Invalid data_type JSON: {e}\"))?;\n        let obj = value\n            .as_object()\n            .ok_or_else(|| anyhow::anyhow!(\"data_type must be a JSON object\"))?;\n        let type_name = obj\n            .get(\"type_name\")\n            .and_then(|v| v.as_str())\n            .ok_or_else(|| anyhow::anyhow!(\"data_type must have type_name\"))?;\n        let metadata = obj.get(\"metadata\").and_then(|m| {\n            if m.is_null() {\n                None\n            } else {\n                let p: Params = serde_json::from_value(m.clone()).ok()?;\n                if p.is_empty() { None } else { Some(p) }\n            }\n        });\n        let identifier = obj\n            .get(\"identifier\")\n            .and_then(|v| v.as_str())","sourceCodeStart":787,"sourceCodeEnd":823,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/mod.rs#L787-L823","documentation":"`DataType::from_persistence_json` parses a persisted `DataType` from a JSON string. If the string is not syntactically valid JSON, `serde_json::from_str` fails and the serde error is wrapped as `Invalid data_type JSON: {e}`.","triggerScenarios":"Calling `DataType::from_persistence_json` with a string that is truncated, empty, concatenated with other log text, or otherwise not valid JSON (e.g. a single-quoted or comment-containing string).","commonSituations":"Reading a corrupted or partially written catalog/journal file; copy-pasting a DataType repr instead of its JSON; a persistence file written by an older version with a different format; loading a file with BOM or trailing garbage bytes.","solutions":["Print the failing string (from the serde error offset) and validate it with a JSON linter to find the syntax fault.","Check the source file for truncation/corruption; restore from backup or re-persist the DataType.","Ensure you pass only the JSON document, not surrounding log lines or a Python/Rust debug repr.","Strip BOM/whitespace and confirm file encoding (UTF-8) before parsing."],"exampleFix":"// before\nlet dt = DataType::from_persistence_json(&raw_line)?;\n\n// after\nlet trimmed = raw_line.trim().trim_start_matches('\\u{feff}');\nlet dt = DataType::from_persistence_json(trimmed)\n    .with_context(|| format!(\"bad DataType JSON: {trimmed}\"))?;","handlingStrategy":"try-catch","validationCode":"fn is_plausible_json(s: &str) -> bool {\n    serde_json::from_str::<serde_json::Value>(s.trim().trim_start_matches('\\u{feff}')).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match DataType::from_persistence_json(s) {\n    Ok(dt) => dt,\n    Err(e) => { log::warn!(\"skipping bad DataType record: {e}\"); continue; }\n};","preventionTips":["Write persistence files atomically (temp file + rename) to avoid truncation.","Persist only the library's own serialized form, never debug reprs or log lines.","Validate JSON files at load time and quarantine bad records."],"tags":["rust","json","persistence","deserialization"],"backgroundTag":"json-parse-error","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"}