{"record":{"id":"e8f59a573d0fcf35","repo":"nautechsystems/nautilus_trader","slug":"invalid-orderstatus-enum-string-value-was-val","errorCode":null,"errorMessage":"invalid `OrderStatus` enum string value, was '{value}'","messagePattern":"invalid `OrderStatus` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":717,"sourceCode":"pub extern \"C\" fn order_status_to_cstr(value: OrderStatus) -> *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 `OrderStatus` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn order_status_from_cstr(ptr: *const c_char) -> OrderStatus {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        OrderStatus::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `OrderStatus` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub 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)]","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L699-L735","documentation":"order_status_from_cstr converts a C string into an OrderStatus enum via FromStr. If the string matches no variant, the function panics with this message; abort_on_panic converts the panic into a process abort at the FFI boundary so no undefined status value crosses the ABI.","triggerScenarios":"Calling order_status_from_cstr(ptr) with a string not accepted by OrderStatus::from_str, e.g. 'FILLED_PARTIAL', 'Open', 'Canceled' (wrong spelling relative to the enum), an empty string, or a buffer with trailing garbage. Only exact variant strings parse.","commonSituations":"Translating venue order-status vocabulary ('partially_filled', 'cancelled' vs 'CANCELED') directly into the FFI call; replaying persisted events recorded under an older enum vocabulary; passing a Python enum repr; case mismatches.","solutions":["Compare the '{value}' in the panic with the valid OrderStatus variant strings and pass the exact one.","Add an explicit venue-to-Nautilus status mapping for external feed/broker strings.","Whitelist-validate the string in the host language before calling the FFI function.","Trim whitespace and confirm correct NUL-termination of the C string.","Rebuild against the current crate version if statuses were renamed or added."],"exampleFix":"// before\norder_status_from_cstr(\"cancelled\"); // panics: wrong spelling/case\n\n// after\norder_status_from_cstr(\"Canceled\"); // exact OrderStatus variant string","handlingStrategy":"validation","validationCode":"const STATUS_MAP = { partially_filled: \"PartiallyFilled\", cancelled: \"Canceled\", open: \"Submitted\" };\nconst canonical = STATUS_MAP[raw] ?? raw;\nconst ORDER_STATUS_VARIANTS = new Set([\"Initialized\", \"Submitted\", \"Accepted\", \"Rejected\", \"Canceled\", \"Expired\", \"Filled\", \"PartiallyFilled\"]);\nif (!ORDER_STATUS_VARIANTS.has(canonical)) throw new Error(`unsupported OrderStatus: ${raw}`);","typeGuard":"function isOrderStatus(v) { return typeof v === 'string' && ORDER_STATUS_VARIANTS.has(v); }","tryCatchPattern":"Not applicable: abort_on_panic converts the panic into a process abort; try/catch cannot intercept it. Validate/translate status strings before the call.","preventionTips":["Maintain an explicit venue-status to OrderStatus mapping and cover it with tests.","Never pass raw broker status strings across FFI.","Watch spelling/case differences like cancelled vs Canceled.","Diff enum variants against the previous version when upgrading."],"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-14T00:17:10.932Z"}