{"record":{"id":"39d7b89e90fc5eba","repo":"nautechsystems/nautilus_trader","slug":"invalid-recordflag-enum-string-value-was-valu","errorCode":null,"errorMessage":"invalid `RecordFlag` enum string value, was '{value}'","messagePattern":"invalid `RecordFlag` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/ffi/enums.rs","lineNumber":836,"sourceCode":"pub extern \"C\" fn record_flag_to_cstr(value: RecordFlag) -> *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 `RecordFlag` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn record_flag_from_cstr(ptr: *const c_char) -> RecordFlag {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        RecordFlag::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `RecordFlag` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub 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)]","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L818-L854","documentation":"`record_flag_from_cstr` converts a C string into a `RecordFlag` enum for the FFI boundary. It panics via `abort_on_panic` when the string matches no `RecordFlag` variant, since the C ABI cannot propagate a recoverable error. The valid serializations are exactly those produced by `RecordFlag::as_ref()`.","triggerScenarios":"Calling the exported C function `record_flag_from_cstr(ptr)` with a string that is not a valid `RecordFlag` serialization (e.g. \"F_LAST\" vs \"LAST\", wrong case, or trailing whitespace/NUL issues).","commonSituations":"Hand-written ctypes/cffi bindings passing wrong constant names; serialized data from an older nautilus release using renamed flags; confused enums (passing an AggressorSide or PriceType string here).","solutions":["Log the incoming string and match it against the `RecordFlag` variant strings in the model crate.","Generate the string with `record_flag_to_cstr(RecordFlag::F_LAST)` to guarantee a valid round-trip.","Fix constant definitions in the calling language binding to mirror the Rust `as_ref()` values exactly.","Check for whitespace/encoding corruption in the C buffer before the call (trim and ensure NUL-terminated)."],"exampleFix":"// before\nrecord_flag_from_cstr(str_to_cstr(\"last\"));\n// after\nlet flag = RecordFlag::F_LAST;\nrecord_flag_from_cstr(record_flag_to_cstr(flag)); // guaranteed valid","handlingStrategy":"validation","validationCode":"fn is_valid_record_flag(s: &str) -> bool {\n    RecordFlag::from_str(s).is_ok()\n}","typeGuard":"fn as_record_flag(s: &str) -> Option<RecordFlag> {\n    RecordFlag::from_str(s).ok()\n}","tryCatchPattern":null,"preventionTips":["Round-trip through record_flag_to_cstr when generating values","Validate persisted/serialized flags after version upgrades","Do not confuse RecordFlag with other flag enums in the model crate"],"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-14T00:17:10.932Z"}