{"record":{"id":"5a0faf26961e5079","repo":"nautechsystems/nautilus_trader","slug":"invalid-optionkind-enum-string-value-was-valu","errorCode":null,"errorMessage":"invalid `OptionKind` enum string value, was '{value}'","messagePattern":"invalid `OptionKind` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":647,"sourceCode":"pub 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)]\npub unsafe extern \"C\" fn option_kind_from_cstr(ptr: *const c_char) -> OptionKind {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        OptionKind::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `OptionKind` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn oto_trigger_mode_to_cstr(value: OtoTriggerMode) -> *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 `OtoTriggerMode` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L629-L665","documentation":"option_kind_from_cstr converts a C string into an OptionKind enum via FromStr. Unrecognized strings cause a panic with this message; abort_on_panic escalates the panic to a process abort so nothing unwinds across the C ABI. The library accepts only the exact variant strings produced by OptionKind's string conversion.","triggerScenarios":"Calling option_kind_from_cstr(ptr) with a string that is not a valid OptionKind variant, e.g. 'CALL_OPTION', 'Put/Call', 'C', or an empty string. Only strings equal to the enum's variant representations (as defined by its FromStr impl) parse successfully.","commonSituations":"Ingesting option-chain data where the feed uses 'C'/'P' or 'call'/'put' abbreviations instead of the Rust variant spelling; passing a Python enum repr; case mismatches; version drift between caller and library.","solutions":["Compare the '{value}' from the panic message with the valid OptionKind variant strings and pass the exact one (e.g. 'CALL'/'PUT' as defined by the enum).","Add an explicit mapping from feed symbols ('C'/'P') to canonical variant strings before the FFI call.","Whitelist-validate the string in the host language prior to calling.","Ensure the C string is NUL-terminated with no surrounding whitespace.","Rebuild against the current crate version if the enum vocabulary changed."],"exampleFix":"// before\noption_kind_from_cstr(\"C\"); // panics: feed abbreviation\n\n// after\noption_kind_from_cstr(\"CALL\"); // canonical OptionKind variant string","handlingStrategy":"validation","validationCode":"const OPTION_KIND_MAP = { C: \"CALL\", P: \"PUT\" };\nconst canonical = OPTION_KIND_MAP[raw] ?? raw;\nif (canonical !== \"CALL\" && canonical !== \"PUT\") throw new Error(`unsupported OptionKind: ${raw}`);","typeGuard":"function isOptionKind(v) { return v === 'CALL' || v === 'PUT'; }","tryCatchPattern":"Not applicable: abort_on_panic terminates the process; catch blocks never run. Translate and validate before calling option_kind_from_cstr.","preventionTips":["Translate feed codes ('C'/'P') to canonical variant strings at ingestion time.","Never forward raw exchange strings into FFI enum parsers.","Validate both case and content; matching is exact.","Test with real feed samples during integration."],"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"}