{"record":{"id":"a2fb20aa50fd7176","repo":"nautechsystems/nautilus_trader","slug":"invalid-currencytype-enum-string-value-was-va","errorCode":null,"errorMessage":"invalid `CurrencyType` enum string value, was '{value}'","messagePattern":"invalid `CurrencyType` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":505,"sourceCode":"pub extern \"C\" fn currency_type_to_cstr(value: CurrencyType) -> *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 `CurrencyType` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn currency_type_from_cstr(ptr: *const c_char) -> CurrencyType {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        CurrencyType::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `CurrencyType` enum string value, was '{value}'\"))\n    })\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 `InstrumentCloseType` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn instrument_close_type_from_cstr(\n    ptr: *const c_char,\n) -> InstrumentCloseType {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L487-L523","documentation":"`currency_type_from_cstr` parses a C string into the Rust `CurrencyType` enum (FIAT, CRYPTO, COMMODITY, etc.) and panics if the string is not a valid variant. As with the other FFI enum parsers, unknown strings cannot be represented, so the function panics and `abort_on_panic` converts the panic into a process abort at the C boundary. Only canonical strings produced by `currency_type_to_cstr` are accepted.","triggerScenarios":"Calling `currency_type_from_cstr(ptr)` with a non-canonical currency type (e.g. lowercase 'fiat', 'digital', or an empty string), or values copied from another SDK's currency classification.","commonSituations":"Registering currencies via the C API; adapters classifying venue currencies; config files with free-form currency-type text; version drift after enum changes.","solutions":["Log the exact failing string and diff it against the canonical `CurrencyType` variant spellings.","Use the `CurrencyType` enum plus `currency_type_to_cstr` to generate valid strings rather than hand-typing.","Normalize case and trim whitespace before the call; matching is exact.","Maintain an explicit mapping from venue/exchange currency classifications to `CurrencyType` strings.","Validate the input against the accepted set before calling — failure aborts the process."],"exampleFix":"// before\ncur = \"fiat\"\ncurrency_type_from_cstr(cur.encode())\n// after\ncur = \"FIAT\"  # canonical CurrencyType spelling\ncurrency_type_from_cstr(cur.encode())","handlingStrategy":"validation","validationCode":"VALID_CURRENCY_TYPES = {\"FIAT\", \"CRYPTO\", \"COMMODITY\"}  # verify against CurrencyType definition\nassert cur_type_str in VALID_CURRENCY_TYPES, f\"bad CurrencyType: {cur_type_str!r}\"\ncurrency_type_from_cstr(cur_type_str.encode())","typeGuard":"def is_valid_currency_type(s: str) -> bool:\n    return s in VALID_CURRENCY_TYPES  # canonical strings from CurrencyType::as_ref","tryCatchPattern":null,"preventionTips":["Map venue currency classifications to CurrencyType strings explicitly.","Normalize case before the FFI call; 'fiat' != 'FIAT'.","Validate against the canonical set before calling.","Derive strings via currency_type_to_cstr rather than literals.","Re-verify after version upgrades."],"tags":["ffi","rust","panic","enum-parsing","process-abort"],"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"}