{"record":{"id":"1f97aea444dae5d3","repo":"nautechsystems/nautilus_trader","slug":"invalid-baraggregation-enum-string-value-was","errorCode":null,"errorMessage":"invalid `BarAggregation` enum string value, was '{value}'","messagePattern":"invalid `BarAggregation` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":412,"sourceCode":"pub extern \"C\" fn bar_aggregation_to_cstr(value: BarAggregation) -> *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 `BarAggregation` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn bar_aggregation_from_cstr(ptr: *const c_char) -> BarAggregation {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        BarAggregation::from_str(value)\n            .unwrap_or_else(|_| panic!(\"invalid `BarAggregation` enum string value, was '{value}'\"))\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn book_action_to_cstr(value: BookAction) -> *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 `BookAction` variant.\n#[unsafe(no_mangle)]","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L394-L430","documentation":"`bar_aggregation_from_cstr` parses a C string into the Rust `BarAggregation` enum and panics if the string is not a valid variant. This is an FFI-only error: any string outside the canonical aggregation serializations triggers a panic that `abort_on_panic` converts into a process abort. There is no graceful error return; the string must match exactly.","triggerScenarios":"Calling `bar_aggregation_from_cstr(ptr)` with strings like '1min'/'minute' in non-canonical spelling, an empty string, or values copied from another framework's bar-interval vocabulary (e.g. pandas resample codes).","commonSituations":"Configuring bar aggregation intervals in a config file with free-form text; translating from pandas/polars resample names to Nautilus aggregations; version changes renaming aggregation variants.","solutions":["Print the exact failing string and compare with the canonical `BarAggregation` variant strings from the enum's FromStr impl.","Build the string via `bar_aggregation_to_cstr` on the corresponding enum value rather than writing it manually.","Normalize case and trim whitespace before the call.","Add an explicit mapping table from external interval names to `BarAggregation` strings when migrating from another framework.","Pre-validate against the accepted set before the FFI call to avoid a hard process abort."],"exampleFix":"// before\nagg = \"1min\"\nbar_aggregation_from_cstr(agg.encode())\n// after\nagg = \"MINUTE\"  # canonical BarAggregation spelling; derive via bar_aggregation_to_cstr\nbar_aggregation_from_cstr(agg.encode())","handlingStrategy":"validation","validationCode":"VALID_BAR_AGGREGATIONS = {\"MILLISECOND\", \"SECOND\", \"MINUTE\", \"HOUR\", \"DAY\", \"TICK\"}  # from BarAggregation definition\nassert agg_str in VALID_BAR_AGGREGATIONS, f\"bad BarAggregation: {agg_str!r}\"\nbar_aggregation_from_cstr(agg_str.encode())","typeGuard":"def is_valid_bar_aggregation(s: str) -> bool:\n    return s in VALID_BAR_AGGREGATIONS  # canonical strings from BarAggregation::as_ref","tryCatchPattern":null,"preventionTips":["Do not reuse interval vocabulary from pandas/other frameworks; map explicitly to BarAggregation strings.","Normalize case and trim whitespace before the call.","Validate config-supplied aggregation strings against the canonical set.","Generate strings via bar_aggregation_to_cstr from enum values.","Re-check spellings 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"}