{"record":{"id":"a6eb9cff2cea31e7","repo":"nautechsystems/nautilus_trader","slug":"unsupported-canonical-diagnostic-code","errorCode":null,"errorMessage":"unsupported canonical diagnostic code","messagePattern":"unsupported canonical diagnostic code","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/result.rs","lineNumber":412,"sourceCode":"        );\n    }\n    anyhow::ensure!(\n        object.get(\"trader_state\").is_some_and(Value::is_string),\n        \"canonical trader state must be a string\"\n    );\n    Ok(())\n}\n\nfn validate_diagnostics(value: &Value) -> anyhow::Result<()> {\n    let diagnostics = value\n        .as_array()\n        .ok_or_else(|| anyhow::anyhow!(\"canonical diagnostics must be an array\"))?;\n    for diagnostic in diagnostics {\n        let object = diagnostic\n            .as_object()\n            .ok_or_else(|| anyhow::anyhow!(\"canonical diagnostic must be an object\"))?;\n        validate_fields(object, &[\"code\"], \"canonical diagnostic\")?;\n        anyhow::ensure!(\n            object.get(\"code\").and_then(Value::as_str) == Some(\"funding-settlement-failed\"),\n            \"unsupported canonical diagnostic code\"\n        );\n    }\n    Ok(())\n}\n\nfn validate_run(value: &Value) -> anyhow::Result<()> {\n    let object = value\n        .as_object()\n        .ok_or_else(|| anyhow::anyhow!(\"canonical result run must be an object\"))?;\n    validate_fields(\n        object,\n        &[\n            \"backtest_end_ns\",\n            \"backtest_start_ns\",\n            \"iterations\",\n            \"outcome\",","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/result.rs#L394-L430","documentation":"The only diagnostic code accepted in a canonical result document is \"funding-settlement-failed\". validate_diagnostics throws this when a diagnostic object's 'code' is a different string or is not a string at all, refusing unknown or future diagnostic codes.","triggerScenarios":"from_slice with a diagnostic like {\"code\": \"order-rejected\"} or {\"code\": 42}; a producer emitting a new diagnostic code the current schema version does not recognize.","commonSituations":"Documents written by a newer library version introducing new diagnostic codes parsed by an older version; custom tooling inventing its own codes; a null code after failed serialization.","solutions":["Change the diagnostic's code to \"funding-settlement-failed\", the only supported value","Remove unsupported diagnostic entries from the document","If the document came from a newer version, parse it with a matching library version","Ensure the code field is a string, not a number or null"],"exampleFix":"// before\n{\"code\": \"margin-call\"}\n// after\n{\"code\": \"funding-settlement-failed\"}","handlingStrategy":"validation","validationCode":"fn diagnostic_codes_supported(d: &[serde_json::Value]) -> bool {\n    d.iter().all(|x| x.get(\"code\").and_then(|c| c.as_str()) == Some(\"funding-settlement-failed\"))\n}","typeGuard":"fn is_supported_code(v: &serde_json::Value) -> bool {\n    v.get(\"code\").and_then(|c| c.as_str()) == Some(\"funding-settlement-failed\")\n}","tryCatchPattern":"match CanonicalResult::from_slice(&bytes) {\n    Ok(result) => /* use result */,\n    Err(e) if e.to_string().contains(\"unsupported canonical diagnostic code\") => /* drop or remap unsupported diagnostics, or upgrade the library */,\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Only emit the \"funding-settlement-failed\" diagnostic code","Keep reader and writer library versions aligned so new codes are recognized","Validate diagnostic codes before writing the document"],"tags":["json","schema-validation","enum"],"backgroundTag":"invalid-enum-value","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"}