{"record":{"id":"18591602bd262865","repo":"nautechsystems/nautilus_trader","slug":"invalid-assetclass-enum-string-value-was-valu","errorCode":null,"errorMessage":"invalid `AssetClass` enum string value, was '{value}'","messagePattern":"invalid `AssetClass` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":365,"sourceCode":"pub extern \"C\" fn asset_class_to_cstr(value: AssetClass) -> *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 `AssetClass` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn asset_class_from_cstr(ptr: *const c_char) -> AssetClass {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        AssetClass::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `AssetClass` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn instrument_class_to_cstr(value: InstrumentClass) -> *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 `InstrumentClass` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L347-L383","documentation":"This panic is raised by `asset_class_from_cstr`, the C FFI converter from a C string to the Rust `AssetClass` enum. It fires when the input string does not parse as an `AssetClass` variant via `FromStr`. The wrapper executes inside `abort_on_panic`, so an unrecognized value aborts the process instead of returning an error code. Only exact canonical variant strings (as emitted by `asset_class_to_cstr`) are accepted.","triggerScenarios":"Calling `asset_class_from_cstr(ptr)` with a string like 'future' in the wrong case, an external feed's own classification term, an empty string, or any value not exactly matching an `AssetClass` serialization.","commonSituations":"Hard-coding asset class strings in config files; passing exchange/broker asset classifications through unmodified; version drift after a variant rename; typos or case mismatches.","solutions":["Print the offending string and diff it against the canonical `AssetClass` variant strings in the model enums.","Construct the value via the library's `AssetClass` enum and serialize with `asset_class_to_cstr` rather than typing strings by hand.","Normalize case and strip whitespace before the call; the parse is exact-match.","Add an explicit mapping from external feed vocabulary to `AssetClass` strings at the adapter boundary.","Validate against the accepted variant list before calling, since invalid input aborts the process."],"exampleFix":"// before\nasset_class = \"future\"\nasset_class_from_cstr(asset_class.encode())\n// after\nasset_class = \"FUTURE\"  # exact canonical variant spelling\nasset_class_from_cstr(asset_class.encode())","handlingStrategy":"validation","validationCode":"VALID_ASSET_CLASSES = {\"FX\", \"CFD\", \"INDEX\", \"EQUITY\", \"FUTURE\", \"OPTION\"}  # from AssetClass definition\nassert asset_class_str in VALID_ASSET_CLASSES, f\"bad AssetClass: {asset_class_str!r}\"\nasset_class_from_cstr(asset_class_str.encode())","typeGuard":"def is_valid_asset_class(s: str) -> bool:\n    return s in VALID_ASSET_CLASSES  # canonical strings from AssetClass::as_ref","tryCatchPattern":null,"preventionTips":["Normalize case and trim whitespace before any enum-string FFI call.","Map external feed vocabulary to AssetClass explicitly instead of passing it through.","Validate against the accepted variant set before calling; invalid input aborts the process.","Round-trip test hard-coded strings against asset_class_to_cstr output in CI.","Check for renamed variants when upgrading library versions."],"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"}