{"record":{"id":"5cac586d5ace6db9","repo":"nautechsystems/nautilus_trader","slug":"invalid-positionadjustmenttype-enum-string-value","errorCode":null,"errorMessage":"invalid `PositionAdjustmentType` enum string value, was '{value}'","messagePattern":"invalid `PositionAdjustmentType` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":789,"sourceCode":"}\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 `PositionAdjustmentType` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn position_adjustment_type_from_cstr(\n    ptr: *const c_char,\n) -> PositionAdjustmentType {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        PositionAdjustmentType::from_str(value).unwrap_or_else(|_| {\n            panic!(\"invalid `PositionAdjustmentType` enum string value, was '{value}'\")\n        })\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn price_type_to_cstr(value: PriceType) -> *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 `PriceType` variant.","sourceCodeStart":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L771-L807","documentation":"position_adjustment_type_from_cstr converts a C string into a PositionAdjustmentType enum via FromStr. Unrecognized strings panic with this message; abort_on_panic converts the panic into a process abort at the FFI boundary. Only the exact variant strings produced by the enum's string conversions are accepted.","triggerScenarios":"Calling position_adjustment_type_from_cstr(ptr) with a string not accepted by PositionAdjustmentType::from_str, e.g. 'ADD', 'sub', 'RESET_POSITION', or an empty string. Only exact variant strings (as defined by the enum) parse.","commonSituations":"Configuring external position adjustments (e.g. corporate actions, manual reconciliations) over FFI with hand-written type names; case mismatches; whitespace from config parsing; version drift after variant renames.","solutions":["Use the exact PositionAdjustmentType variant string; compare the '{value}' in the panic against the enum's FromStr definition.","Normalize config strings (trim, fix case) before calling the FFI function.","Whitelist-validate the string in the host language before the call.","Confirm the C string is NUL-terminated with no trailing garbage.","Rebuild the caller against the same crate version if the enum vocabulary changed."],"exampleFix":"// before\nposition_adjustment_type_from_cstr(\"ADD\"); // panics: not a variant\n\n// after\nposition_adjustment_type_from_cstr(\"Add\"); // exact PositionAdjustmentType variant string","handlingStrategy":"validation","validationCode":"const POSITION_ADJUSTMENT_TYPE_VARIANTS = new Set([\"Add\", \"Subtract\"]);\nif (typeof adjType !== \"string\" || !POSITION_ADJUSTMENT_TYPE_VARIANTS.has(adjType)) {\n  throw new Error(`unsupported PositionAdjustmentType: ${adjType}`);\n}","typeGuard":"function isPositionAdjustmentType(v) { return typeof v === 'string' && POSITION_ADJUSTMENT_TYPE_VARIANTS.has(v); }","tryCatchPattern":"Not applicable: the panic is converted to a process abort at the FFI boundary and cannot be caught. Validate the adjustment type string before calling position_adjustment_type_from_cstr.","preventionTips":["Source adjustment type strings from the library's enum objects, not literals.","Trim and case-normalize config values, then validate against the exact variant names.","Centralize FFI enum parsing in one validated wrapper.","Rebuild bindings and rerun enum round-trip tests after crate upgrades."],"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"}