{"record":{"id":"566d5851a90554ae","repo":"nautechsystems/nautilus_trader","slug":"invalid-triggertype","errorCode":null,"errorMessage":"Invalid `TriggerType`","messagePattern":"Invalid `TriggerType`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/infrastructure/src/sql/models/orders.rs","lineNumber":1257,"sourceCode":"        decoded\n            .into_iter()\n            .map(|(k, v)| (Ustr::from(k.as_str()), Ustr::from(v.as_str())))\n            .collect(),\n    ))\n}\n\nfn tags_from_row(row: &PgRow) -> Option<Vec<Ustr>> {\n    row.try_get::<Vec<String>, _>(\"tags\")\n        .ok()\n        .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","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/models/orders.rs#L1239-L1275","documentation":"`parse_trigger_type` converts the optional `trigger_type` column into an `Option<TriggerType>`: the sentinel string 'NO_TRIGGER' (case-insensitive) maps to None, anything else is parsed with `TriggerType::from_str` and unwrapped with expect(). The panic means the stored trigger type string is neither the sentinel nor a valid TriggerType variant (expected e.g. 'DEFAULT','BID','ASK','LAST',...).","triggerScenarios":"Calling `OrderModel::from_row` (via parse_trigger_type) where `trigger_type` holds an unrecognized value: 'DEFAULT ' with whitespace, lowercase variants if the parser is case-sensitive, adapter-specific names like 'MARK', or NULL-handling gone wrong upstream.","commonSituations":"Rows written by other systems or older nautilus versions with different trigger naming; manual inserts; adapters mapping exchange trigger kinds to non-canonical strings.","solutions":["Audit values: `SELECT DISTINCT trigger_type FROM orders` and fix anything outside the valid set plus 'NO_TRIGGER'","Make the writer persist canonical TriggerType strings (or the NO_TRIGGER sentinel)","Trim/uppercase the column via migration if only formatting differs","Return an error instead of expect when deserializing untrusted rows"],"exampleFix":"// before\nSome(TriggerType::from_str(value).expect(\"Invalid `TriggerType`\"))\n// after\nTriggerType::from_str(value.trim())\n    .map(Some)\n    .map_err(|e| ModelError::Parse(format!(\"invalid trigger_type '{value}': {e}\")))?","handlingStrategy":"type-guard","validationCode":"fn valid_trigger_type(s: Option<&str>) -> bool {\n    s.map(|s| s.eq_ignore_ascii_case(\"NO_TRIGGER\") || TriggerType::from_str(s).is_ok()).unwrap_or(true)\n}","typeGuard":"fn is_known_trigger_type(s: &str) -> bool {\n    s.eq_ignore_ascii_case(\"NO_TRIGGER\") || TriggerType::from_str(s).is_ok()\n}","tryCatchPattern":"TriggerType::from_str(value.trim())\n    .map(Some)\n    .map_err(|e| ModelError::Parse(format!(\"row: invalid trigger_type '{value}': {e}\")))?","preventionTips":["Use the 'NO_TRIGGER' sentinel exactly as defined for absent triggers","Persist TriggerType via canonical serialization only","Normalize (trim) values at write time","Audit trigger_type values after adapter or nautilus version changes"],"tags":["rust","sql","postgres","enum","panic"],"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"}