{"record":{"id":"679b55a62e131c72","repo":"nautechsystems/nautilus_trader","slug":"invalid-timeinforce","errorCode":null,"errorMessage":"Invalid `TimeInForce`","messagePattern":"Invalid `TimeInForce`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/infrastructure/src/sql/models/orders.rs","lineNumber":1094,"sourceCode":"            .try_get::<Option<&str>, _>(\"trigger_type\")\n            .ok()\n            .and_then(parse_trigger_type);\n        let limit_offset = row\n            .try_get::<Option<&str>, _>(\"limit_offset\")\n            .ok()\n            .and_then(|x| x.and_then(|s| Decimal::from_str(s).ok()));\n        let trailing_offset = row\n            .try_get::<Option<&str>, _>(\"trailing_offset\")\n            .ok()\n            .and_then(|x| x.and_then(|s| Decimal::from_str(s).ok()));\n        let trailing_offset_type = row\n            .try_get::<Option<TrailingOffsetTypePg>, _>(\"trailing_offset_type\")\n            .ok()\n            .flatten()\n            .and_then(|value| value.0);\n        let time_in_force = row\n            .try_get::<&str, _>(\"time_in_force\")\n            .map(|x| TimeInForce::from_str(x).expect(\"Invalid `TimeInForce`\"))?;\n        let expire_time = row\n            .try_get::<Option<&str>, _>(\"expire_time\")\n            .ok()\n            .and_then(|x| x.map(UnixNanos::from));\n        let filled_qty = row.try_get::<&str, _>(\"filled_qty\").map(Quantity::from)?;\n        let liquidity_side = row\n            .try_get::<Option<&str>, _>(\"liquidity_side\")\n            .ok()\n            .and_then(|x| x.map(|x| LiquiditySide::from_str(x).expect(\"Invalid `LiquiditySide`\")));\n        let avg_px = row.try_get::<Option<Decimal>, _>(\"avg_px\").ok().flatten();\n        let slippage = row.try_get::<Option<Decimal>, _>(\"slippage\").ok().flatten();\n        let commissions = row\n            .try_get::<Option<Vec<String>>, _>(\"commissions\")?\n            .map_or_else(Vec::new, |c| {\n                c.into_iter().map(|s| Money::from(&s)).collect()\n            });\n        let status = row\n            .try_get::<&str, _>(\"status\")","sourceCodeStart":1076,"sourceCodeEnd":1112,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/models/orders.rs#L1076-L1112","documentation":"The `time_in_force` column string is parsed with `TimeInForce::from_str` and unwrapped with expect() while loading an order row. The panic indicates the stored TIF value (expected e.g. 'GTC','IOC','FOK','GTD','DAY','AT_THE_OPEN'...) is not a recognized variant, so the row cannot be reconstructed.","triggerScenarios":"Calling `OrderModel::from_row` where `time_in_force` contains an unknown/misspelled/case-mismatched value, e.g. 'Good Till Cancel', 'gtc ' with whitespace, or an exchange-specific TIF not in the enum.","commonSituations":"Older schema versions or migrations that rewrote TIF values; adapter-specific persistence layers; manual CSV imports into the orders table.","solutions":["Locate bad rows with `SELECT id, time_in_force FROM orders WHERE time_in_force NOT IN (...)` and correct them","Fix the insertion path to serialize TimeInForce canonically","Trim/uppercase the stored values via migration if formatting is the issue","Return a parse error rather than expect for untrusted data sources"],"exampleFix":"// before\nTimeInForce::from_str(x).expect(\"Invalid `TimeInForce`\")\n// after\nTimeInForce::from_str(x.trim()).map_err(|e| ModelError::Parse(format!(\"invalid time_in_force '{x}': {e}\")))?","handlingStrategy":"type-guard","validationCode":"const VALID_TIF: &[&str] = &[\"GTC\",\"IOC\",\"FOK\",\"GTD\",\"DAY\",\"AT_THE_OPEN\",\"AT_THE_CLOSE\"];\nassert!(VALID_TIF.contains(&tif_str.trim()), \"bad time_in_force: {tif_str}\");","typeGuard":"fn is_known_time_in_force(s: &str) -> bool {\n    TimeInForce::from_str(s.trim()).is_ok()\n}","tryCatchPattern":"let tif = TimeInForce::from_str(x.trim())\n    .map_err(|e| ModelError::Parse(format!(\"row {}: invalid time_in_force '{x}': {e}\", row_id)))?;","preventionTips":["Persist TIF via the enum's canonical string conversion","Add a CHECK constraint on time_in_force","Trim and normalize before insert","Cover all TimeInForce variants in persistence round-trip tests"],"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"}