{"record":{"id":"f2adcf39a2c539c5","repo":"nautechsystems/nautilus_trader","slug":"invalid-tradingstate-enum-string-value-was-va","errorCode":null,"errorMessage":"invalid `TradingState` enum string value, was '{value}'","messagePattern":"invalid `TradingState` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/ffi/enums.rs","lineNumber":882,"sourceCode":"pub 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)]\npub unsafe extern \"C\" fn trading_state_from_cstr(ptr: *const c_char) -> TradingState {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        TradingState::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `TradingState` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn trailing_offset_type_to_cstr(value: TrailingOffsetTypeOptional) -> *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 `TrailingOffsetTypeOptional` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L864-L900","documentation":"`trading_state_from_cstr` parses a C string into the `TradingState` enum (e.g. ACTIVE, REDUCED, HALTED, HOLD). Invalid strings cause a panic wrapped in `abort_on_panic`, terminating the process, because the C ABI offers no error channel. Only exact variant serializations from `TradingState::as_ref()` are accepted.","triggerScenarios":"Calling the exported `trading_state_from_cstr` with any string not exactly equal to a `TradingState` variant serialization, such as \"active\" (lowercase) or \"trading\".","commonSituations":"Custom adapters emitting their own state names; stale persisted state files from older versions with renamed variants; copy-pasted enum strings from a different nautilus enum.","solutions":["Diff the failing string against the `TradingState` variant list and use the exact canonical name.","Produce strings via `trading_state_to_cstr(TradingState::Active)` rather than literals.","Whitelist/validate trading-state strings in the adapter or config layer before FFI calls.","If migrating versions, remap old variant names to the current ones in your data pipeline."],"exampleFix":"// before\ntrading_state_from_cstr(str_to_cstr(\"active\"));\n// after\ntrading_state_from_cstr(str_to_cstr(\"ACTIVE\"));","handlingStrategy":"validation","validationCode":"fn is_valid_trading_state(s: &str) -> bool {\n    TradingState::from_str(s).is_ok()\n}","typeGuard":"fn as_trading_state(s: &str) -> Option<TradingState> {\n    TradingState::from_str(s).ok()\n}","tryCatchPattern":null,"preventionTips":["Use exact canonical variant names (e.g. ACTIVE, HALTED) in all adapters","Whitelist trading-state strings from external systems before conversion","Remap old variant names when migrating nautilus versions"],"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"}