{"record":{"id":"dda9617705337ccd","repo":"nautechsystems/nautilus_trader","slug":"invalid-ordertype-enum-string-value-was-value","errorCode":null,"errorMessage":"invalid `OrderType` enum string value, was '{value}'","messagePattern":"invalid `OrderType` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":740,"sourceCode":"pub extern \"C\" fn order_type_to_cstr(value: OrderType) -> *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 `OrderType` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn order_type_from_cstr(ptr: *const c_char) -> OrderType {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        OrderType::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `OrderType` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn position_side_to_cstr(value: PositionSideOptional) -> *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 `PositionSideOptional` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L722-L758","documentation":"order_type_from_cstr converts a C string into an OrderType enum via FromStr. Unrecognized strings panic with this message, and abort_on_panic escalates the panic to a process abort at the FFI boundary. The library accepts only the exact variant strings emitted by OrderType's string conversions.","triggerScenarios":"Calling order_type_from_cstr(ptr) with strings like 'LIMIT_ORDER', 'MKT', 'StopLimit', 'bracket', or an empty string that do not match any OrderType variant. Only strings accepted by OrderStatus's sibling impl OrderType::from_str parse.","commonSituations":"Mapping venue order-type codes ('MKT', 'LMT', 'STP') directly into the FFI call without translation; building orders from config files with hand-written type names; case mismatches; version drift after enum renames.","solutions":["Pass the exact OrderType variant string; verify against the '{value}' in the panic and the enum's FromStr definition.","Translate venue-specific codes ('MKT'/'LMT') to canonical variant names in the caller before calling.","Validate the string against the variant whitelist in the host language.","Ensure the C string is exact and NUL-terminated with no stray whitespace.","Rebuild the caller against the matching crate version if the enum vocabulary changed."],"exampleFix":"// before\norder_type_from_cstr(\"MKT\"); // panics: venue code\n\n// after\norder_type_from_cstr(\"MARKET\"); // canonical OrderType variant string","handlingStrategy":"validation","validationCode":"const TYPE_MAP = { MKT: \"MARKET\", LMT: \"LIMIT\", STP: \"STOP\" };\nconst canonical = TYPE_MAP[raw] ?? raw;\nconst ORDER_TYPE_VARIANTS = new Set([\"MARKET\", \"LIMIT\", \"STOP_MARKET\", \"STOP_LIMIT\", \"MARKET_TO_LIMIT\", \"MARKET_IF_TOUCHED\", \"LIMIT_IF_TOUCHED\", \"TRAILING_STOP_MARKET\"]);\nif (!ORDER_TYPE_VARIANTS.has(canonical)) throw new Error(`unsupported OrderType: ${raw}`);","typeGuard":"function isOrderType(v) { return typeof v === 'string' && ORDER_TYPE_VARIANTS.has(v); }","tryCatchPattern":"Not applicable: the panic aborts the process; cannot be caught from the host language. Translate venue codes and validate before order_type_from_cstr.","preventionTips":["Translate venue order-type abbreviations ('MKT', 'LMT') at the adapter layer.","Build orders through typed constructors/enums, not raw strings.","Whitelist-validated values in wrappers around all FFI enum parsers.","Test order construction with each supported type after upgrades."],"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"}