{"record":{"id":"2ce79f5ba74be25b","repo":"nautechsystems/nautilus_trader","slug":"invalid-timeinforce-enum-string-value-was-val","errorCode":null,"errorMessage":"invalid `TimeInForce` enum string value, was '{value}'","messagePattern":"invalid `TimeInForce` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/ffi/enums.rs","lineNumber":859,"sourceCode":"pub extern \"C\" fn time_in_force_to_cstr(value: TimeInForce) -> *const c_char {\n    str_to_cstr(value.as_ref())\n}\n\n/// Returns an enum from a C string.\n///\n/// # Safety\n///\n/// Assumes `ptr` is a valid C string pointer.\n///\n/// # Panics\n///\n/// Panics if the C string does not correspond to a valid `TimeInForce` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn time_in_force_from_cstr(ptr: *const c_char) -> TimeInForce {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        TimeInForce::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `TimeInForce` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn trading_state_to_cstr(value: TradingState) -> *const c_char {\n    str_to_cstr(value.as_ref())\n}\n\n/// Returns an enum from a C string.\n///\n/// # Safety\n///\n/// Assumes `ptr` is a valid C string pointer.\n///\n/// # Panics\n///\n/// Panics if the C string does not correspond to a valid `TradingState` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L841-L877","documentation":"`time_in_force_from_cstr` parses a C string into a `TimeInForce` enum at the FFI boundary. On any string that does not correspond to a `TimeInForce` variant (GTC, IOC, FOK, GTD, DAY, AT_THE_OPEN, AT_THE_CLOSE, etc.) it panics inside `abort_on_panic`, aborting the process rather than returning an error. This enforces that only canonical enum serializations cross the C ABI.","triggerScenarios":"Calling `time_in_force_from_cstr(ptr)` with an unsupported or misspelled TIF string, such as \"GTC \" with trailing space, \"GoodTillCancel\", or a broker-specific value like \"OPG\" that the enum does not define.","commonSituations":"Mapping broker/exchange TIF codes (e.g. FIX tag 59 values) directly to nautilus strings without translation; adapters passing lowercase values; enum renamed between nautilus releases breaking persisted configs.","solutions":["Compare the failing string against the canonical `TimeInForce` variant names and correct the caller.","Translate exchange/FIX TIF codes to nautilus `TimeInForce` variants in an adapter layer before crossing FFI.","Use `time_in_force_to_cstr` on the enum to build valid input strings programmatically.","Validate/whitelist TIF values in your config parsing before they reach the FFI call."],"exampleFix":"// before\ntime_in_force_from_cstr(str_to_cstr(\"GoodTillCancelled\"));\n// after\ntime_in_force_from_cstr(str_to_cstr(\"GTC\"));","handlingStrategy":"validation","validationCode":"fn is_valid_tif(s: &str) -> bool {\n    TimeInForce::from_str(s).is_ok()\n}","typeGuard":"fn as_time_in_force(s: &str) -> Option<TimeInForce> {\n    TimeInForce::from_str(s).ok()\n}","tryCatchPattern":null,"preventionTips":["Translate exchange/FIX TIF codes to canonical nautilus variants in adapters","Validate TIF config values at startup, not at trade time","Use enum objects (PyO3 class) in Python instead of raw strings"],"tags":["ffi","rust","enum-parsing","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"}