{"record":{"id":"0d2ad2ae0a65b28f","repo":"nautechsystems/nautilus_trader","slug":"invalid-contingencytype","errorCode":null,"errorMessage":"Invalid `ContingencyType`","messagePattern":"Invalid `ContingencyType`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/models/orders.rs","lineNumber":1267,"sourceCode":"        .map(|tags| tags.iter().map(|tag| Ustr::from(tag.as_str())).collect())\n}\n\nfn parse_trigger_type(value: Option<&str>) -> Option<TriggerType> {\n    value.and_then(|value| {\n        if value.eq_ignore_ascii_case(\"NO_TRIGGER\") {\n            None\n        } else {\n            Some(TriggerType::from_str(value).expect(\"Invalid `TriggerType`\"))\n        }\n    })\n}\n\nfn parse_contingency_type(value: Option<&str>) -> Option<ContingencyType> {\n    value.and_then(|value| {\n        if value.eq_ignore_ascii_case(\"NO_CONTINGENCY\") {\n            None\n        } else {\n            Some(ContingencyType::from_str(value).expect(\"Invalid `ContingencyType`\"))\n        }\n    })\n}\n\n#[cfg(test)]\nmod tests {\n    use rstest::rstest;\n\n    use super::*;\n\n    #[rstest]\n    #[case(None, None)]\n    #[case(Some(\"NO_TRIGGER\"), None)]\n    #[case(Some(\"LAST_PRICE\"), Some(TriggerType::LastPrice))]\n    fn test_parse_trigger_type_accepts_legacy_absence(\n        #[case] value: Option<&str>,\n        #[case] expected: Option<TriggerType>,\n    ) {","sourceCodeStart":1249,"sourceCodeEnd":1285,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/models/orders.rs#L1249-L1285","documentation":"This panic comes from `parse_contingency_type` in the SQL order model when deserializing a persisted contingency type string. The code maps the sentinel value 'NO_CONTINGENCY' to `None` and otherwise delegates to `ContingencyType::from_str`, panicking via `.expect(\"Invalid `ContingencyType`\")` if the string is not a recognized `ContingencyType` variant. It is a data-integrity guard: the database is expected to contain only valid enum values written by this library.","triggerScenarios":"Reading an `orders` row whose `contingency_type` column holds a string that is not a valid `ContingencyType` variant (and is not 'NO_CONTINGENCY') — e.g. an empty string, a manually inserted/edited DB value, a typo like 'OC0' instead of 'OCO', or a value written by a newer/older schema version the current code cannot parse.","commonSituations":"Hand-written SQL migrations or seed data inserting raw contingency strings; rows written by a different nautilus version whose enum spelling changed; ETL scripts copying values from another schema; manual DB fixes.","solutions":["Inspect the offending row (`SELECT contingency_type FROM orders WHERE ...`) and correct it to a valid `ContingencyType` value or 'NO_CONTINGENCY'","List distinct `contingency_type` values and compare against the valid `ContingencyType` variants (e.g. OTO, OCO, OUO)","Fix the writer that inserted the bad value so it serializes the enum through the library's serializer instead of a hand-built string","If the value is a valid variant from a newer version, upgrade nautilus so `ContingencyType::from_str` recognizes it"],"exampleFix":"// before (bad row value)\ncontingency_type = 'OC0'\n// after\ncontingency_type = 'OCO'","handlingStrategy":"validation","validationCode":"fn is_valid_contingency(value: &str) -> bool {\n    value.eq_ignore_ascii_case(\"NO_CONTINGENCY\") || ContingencyType::from_str(value).is_some()\n}\n// call before reading/accepting rows: if !is_valid_contingency(s) { reject row }","typeGuard":"fn valid_contingency(s: &str) -> Option<ContingencyType> {\n    if s.eq_ignore_ascii_case(\"NO_CONTINGENCY\") { None } else { ContingencyType::from_str(s) }\n}","tryCatchPattern":null,"preventionTips":["Only write `ContingencyType` values through the library serializer","Validate enum strings before inserting rows manually or via ETL","Keep writer and reader nautilus versions aligned"],"tags":["database","parsing","panic","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-14T00:17:10.932Z"}