{"record":{"id":"e23e64ea35f53522","repo":"nautechsystems/nautilus_trader","slug":"invalid-aggregationsource-enum-string-value-was","errorCode":null,"errorMessage":"invalid `AggregationSource` enum string value, was '{value}'","messagePattern":"invalid `AggregationSource` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":318,"sourceCode":"pub extern \"C\" fn aggregation_source_to_cstr(value: AggregationSource) -> *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 `AggregationSource` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn aggregation_source_from_cstr(ptr: *const c_char) -> AggregationSource {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        AggregationSource::from_str(value).unwrap_or_else(|_| {\n            panic!(\"invalid `AggregationSource` enum string value, was '{value}'\")\n        })\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn aggressor_side_to_cstr(value: AggressorSide) -> *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 `AggressorSide` variant.","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L300-L336","documentation":"FFI helper aggregation_source_from_cstr converts a C string to the AggregationSource enum and panics (aborting via abort_on_panic) when the value does not parse. As with all FFI boundary panics, the process aborts rather than unwinding, so the host cannot recover.","triggerScenarios":"Passing a C string that is not a valid AggregationSource variant (e.g. 'EXTERNAL' vs expected 'NO_INTERNET'/'INTERNET' style values) to aggregation_source_from_cstr.","commonSituations":"Config strings from another system using different naming for data aggregation source; stale bindings after an enum rename; typos or lowercasing in config files consumed by the C/Python layer.","solutions":["Use the exact accepted AggregationSource strings (check the Rust enum's FromStr impl)","Validate the string in the host language before crossing the FFI boundary","Regenerate/sync bindings after upgrading nautilus_model"],"exampleFix":"// before\nlet src = aggregation_source_from_cstr(c\"external\"); // invalid -> abort\n// after\nlet src = aggregation_source_from_cstr(c\"EXTERNAL\"); // must match enum values exactly","handlingStrategy":"validation","validationCode":"// Host-side validation before the FFI call\nVALID_SOURCES = {\"NO_INTERNET\", \"INTERNET\"}  # match AggregationSource variants\nif value not in VALID_SOURCES:\n    raise ValueError(f\"invalid AggregationSource: {value!r}\")","typeGuard":null,"tryCatchPattern":"// FFI panics abort, so validate before crossing the boundary\nassert!(VALID.contains(&value.as_str()), \"invalid AggregationSource: {value}\");\nlet source = unsafe { aggregation_source_from_cstr(ptr) };","preventionTips":["Mirror enum values exactly in host-language configs and validate on load","Regenerate bindings after any model upgrade so string tables match","Log and reject invalid enum strings at config-parse time, not at FFI call time"],"tags":["rust","ffi","panic-abort","enum-parsing"],"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"}