{"record":{"id":"dd45066945d605f7","repo":"nautechsystems/nautilus_trader","slug":"invalid-marketstatus-enum-string-value-was-va","errorCode":null,"errorMessage":"invalid `MarketStatus` enum string value, was '{value}'","messagePattern":"invalid `MarketStatus` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":577,"sourceCode":"pub extern \"C\" fn market_status_to_cstr(value: MarketStatus) -> *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 `MarketStatus` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn market_status_from_cstr(ptr: *const c_char) -> MarketStatus {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        MarketStatus::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `MarketStatus` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn market_status_action_to_cstr(value: MarketStatusAction) -> *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 `MarketStatusAction` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L559-L595","documentation":"market_status_from_cstr converts a C string into a MarketStatus enum via FromStr. If the string does not match any MarketStatus variant, the function panics with this message (wrapped by abort_on_panic, which aborts the process instead of unwinding across the FFI boundary). This library panics deliberately at the FFI edge because there is no Result-based error channel across the C ABI.","triggerScenarios":"Calling the exported C function market_status_from_cstr(ptr) with a pointer to a string that is not a valid MarketStatus variant string, e.g. 'OPEN_MARKET', 'open ', 'trading', an empty string, or a stale/garbage pointer buffer. Any value not produced by MarketStatus.as_ref()/ToString will panic.","commonSituations":"Passing a Python/other-language enum value whose str() rendering differs from the Rust variant name (e.g. 'MarketStatus.OPEN' or '1'); receiving a status string from a broker feed that uses different vocabulary; upgrading NautilusTrader where a variant was renamed or removed; building the C string with a wrong length so trailing garbage is included.","solutions":["Print or log the offending '{value}' from the panic message and compare it against the valid MarketStatus variant strings (as defined by MarketStatus::from_str / as_ref in the model enums).","Fix the caller to pass the exact variant spelling (case-sensitive) expected by the Rust enum.","Validate/whitelist the incoming string in the foreign-language code before calling the FFI function.","If the string comes from an external feed, map it to a valid MarketStatus variant explicitly instead of forwarding raw text.","Check for a version mismatch: rebuild the calling code against the same crate version so enum names match."],"exampleFix":"// before\nconst char* s = \"OPEN_MARKET\";\nMarketStatus st = market_status_from_cstr(s); // panics\n\n// after\nconst char* s = \"open\"; // exact MarketStatus variant string\nMarketStatus st = market_status_from_cstr(s);","handlingStrategy":"validation","validationCode":"const MARKET_STATUS_VARIANTS = new Set([\"pre_open\", \"open\", \"pause\", \"pre_close\", \"close\", \"post_close\", \"auction\"]);\nfunction isValidMarketStatus(s) { return typeof s === \"string\" && MARKET_STATUS_VARIANTS.has(s); }\nif (!isValidMarketStatus(value)) throw new Error(`unsupported MarketStatus: ${value}`);","typeGuard":"function isMarketStatus(v) { return typeof v === 'string' && MARKET_STATUS_VARIANTS.has(v); }","tryCatchPattern":"Not applicable: the Rust side aborts the process on panic (abort_on_panic), so it cannot be caught in-process. Validate before calling market_status_from_cstr.","preventionTips":["Always source enum strings from the library's own enum objects, never hand-write them.","Trim and case-check strings from configs or external feeds before FFI calls.","Whitelist known variant strings in host-language wrappers.","Pin the crate version and rebuild bindings after upgrades in case variants are renamed."],"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"}