{"record":{"id":"6df402e8d4f146cb","repo":"nautechsystems/nautilus_trader","slug":"invalid-pricetype-enum-string-value-was-value","errorCode":null,"errorMessage":"invalid `PriceType` enum string value, was '{value}'","messagePattern":"invalid `PriceType` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/ffi/enums.rs","lineNumber":813,"sourceCode":"pub extern \"C\" fn price_type_to_cstr(value: PriceType) -> *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 `PriceType` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn price_type_from_cstr(ptr: *const c_char) -> PriceType {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        PriceType::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `PriceType` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub 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)]","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L795-L831","documentation":"NautilusTrader's FFI layer exposes `price_type_from_cstr` to convert a C string into a `PriceType` enum. The library panics when the string does not match any `PriceType` variant (e.g. \"LIMIT\" vs \"MID\"). Because the FFI boundary cannot return Result types, invalid input is treated as a programming error and aborted via `abort_on_panic`.","triggerScenarios":"Calling the C FFI function `price_type_from_cstr(ptr)` with a pointer to a string that is not a valid `PriceType` serialization (typo, wrong casing, truncated string, or a value from a different enum).","commonSituations":"Passing Python enum `.value` strings that differ from Rust `as_ref()` names after a version upgrade; hand-built C bindings sending lowercase like \"limit\" instead of \"LIMIT\"; buffer misalignment producing garbage strings.","solutions":["Print the exact string being passed and compare against the `PriceType` variants in crates/model/src/enums (use the documented 'LIMIT', 'MARKET', etc. serializations).","Use the provided `price_type_to_cstr` round-trip to generate valid strings instead of hand-writing them.","In Python bindings, construct the enum via the `PriceType` PyO3 class rather than passing raw strings across FFI.","If a variant was removed/renamed in a newer nautilus version, update the caller to the current variant names."],"exampleFix":"// before\nlet ptr = str_to_cstr(\"Mid\");\nlet pt = price_type_from_cstr(ptr);\n// after\nlet ptr = price_type_to_cstr(PriceType::Last); // or exact variant string \"LAST\"\nlet pt = price_type_from_cstr(ptr);","handlingStrategy":"validation","validationCode":"// Caller side (Rust)\nfn is_valid_price_type(s: &str) -> bool {\n    PriceType::from_str(s).is_ok()\n}\n// assert!(is_valid_price_type(value)); before price_type_from_cstr","typeGuard":"fn as_price_type(s: &str) -> Option<PriceType> {\n    PriceType::from_str(s).ok()\n}","tryCatchPattern":null,"preventionTips":["Always derive strings via price_type_to_cstr rather than hand-written literals","Whitelist-validate enum strings in adapter/config layers before FFI calls","Keep bindings' constant tables in sync when upgrading nautilus_model","Watch for casing and whitespace in cross-language string handling"],"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-14T05:17:10.506Z"}