{"record":{"id":"269db8ed367495c3","repo":"nautechsystems/nautilus_trader","slug":"invalid-omstype-enum-string-value-was-value","errorCode":null,"errorMessage":"invalid `OmsType` enum string value, was '{value}'","messagePattern":"invalid `OmsType` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":624,"sourceCode":"pub extern \"C\" fn oms_type_to_cstr(value: OmsType) -> *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 `OmsType` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn oms_type_from_cstr(ptr: *const c_char) -> OmsType {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        OmsType::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `OmsType` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn option_kind_to_cstr(value: OptionKind) -> *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 `OptionKind` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L606-L642","documentation":"oms_type_from_cstr converts a C string into an OmsType enum via FromStr. If the string matches no OmsType variant, the function panics with this message, and abort_on_panic converts the panic into a process abort at the FFI boundary. This guards against ever returning an undefined enum discriminant to C callers.","triggerScenarios":"Calling oms_type_from_cstr(ptr) with a string that is not a valid OmsType variant, e.g. 'NETTING_GROSS', 'Hedging', '1', or an empty string. Valid values are only those accepted by OmsType::from_str (the variant names such as 'Netting', 'Hedging').","commonSituations":"Configuring an engine over FFI with an OMS type spelled differently than the Rust variant; passing a numeric config value where the string name is required; locale/case mistakes ('hedging' vs 'Hedging'); switching crate versions where the enum vocabulary changed.","solutions":["Use the exact OmsType variant string shown in the panic's '{value}' comparison — check the enum definition for accepted spellings (case-sensitive).","Map config values to canonical variant names before calling the FFI function.","Validate the string against the enumerated variant list in the host language.","Fix buffer construction so the C string is exact and NUL-terminated (no whitespace or trailing bytes).","Align crate versions between the caller and the library if variants were renamed."],"exampleFix":"// before\noms_type_from_cstr(\"netting\"); // panics: wrong case\n\n// after\noms_type_from_cstr(\"Netting\"); // exact OmsType variant string","handlingStrategy":"validation","validationCode":"const OMS_TYPE_VARIANTS = new Set([\"Netting\", \"Hedging\"]);\nif (typeof omsType !== \"string\" || !OMS_TYPE_VARIANTS.has(omsType)) {\n  throw new Error(`unsupported OmsType: ${omsType}`);\n}","typeGuard":"function isOmsType(v) { return typeof v === 'string' && OMS_TYPE_VARIANTS.has(v); }","tryCatchPattern":"Not applicable: the panic aborts the process; cannot be caught across FFI. Guard with pre-call validation.","preventionTips":["Read OMS type from config as a string and validate against the exact variant names (case-sensitive).","Reject numeric or abbreviated config values at config-load time.","Centralize all FFI enum conversions in one validated wrapper module.","Keep bindings regenerated in sync with crate version."],"tags":["ffi","panic","enum-parsing","rust"],"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"}