{"record":{"id":"682b7d0f0f301dca","repo":"nautechsystems/nautilus_trader","slug":"invalid-positionsideoptional-enum-string-value","errorCode":null,"errorMessage":"invalid `PositionSideOptional` enum string value, was '{value}'","messagePattern":"invalid `PositionSideOptional` enum string value, was '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/ffi/enums.rs","lineNumber":763,"sourceCode":"pub extern \"C\" fn position_side_to_cstr(value: PositionSideOptional) -> *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 `PositionSideOptional` variant.\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn position_side_from_cstr(ptr: *const c_char) -> PositionSideOptional {\n    abort_on_panic(|| {\n        let value = unsafe { cstr_as_str(ptr) };\n        PositionSideOptional::from_str(value).unwrap_or_else(|_| {\n            panic!(\"invalid `PositionSideOptional` enum string value, was '{value}'\")\n        })\n    })\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn position_adjustment_type_to_cstr(value: PositionAdjustmentType) -> *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 `PositionAdjustmentType` variant.","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/ffi/enums.rs#L745-L781","documentation":"position_side_from_cstr converts a C string into a PositionSideOptional enum via FromStr. If the string matches no variant the function panics with this message; abort_on_panic converts the panic into a process abort at the FFI boundary. This mirrors order_side_from_cstr but for position sides, including a none/flat variant.","triggerScenarios":"Calling position_side_from_cstr(ptr) with strings like 'LONG_POSITION', 'short', '0', or an empty string that match no PositionSideOptional variant. Empty input does not map to the none variant — the explicit none-variant string must be used.","commonSituations":"Mapping broker position directions ('long'/'short', 'net long') directly into the FFI call; passing empty/None where the explicit none-variant string is required; case mismatches; version drift after a variant rename.","solutions":["Pass the exact PositionSideOptional variant string (e.g. 'LONG', 'SHORT', or the none-variant string) per the enum's FromStr definition.","Use the explicit none/flat variant string instead of an empty string for neutral positions.","Map feed-specific direction vocabulary to canonical variants in the caller.","Whitelist-validate the string before the FFI call.","Rebuild against the matching crate version if variants were renamed."],"exampleFix":"// before\nposition_side_from_cstr(\"short\"); // panics: wrong case\n\n// after\nposition_side_from_cstr(\"SHORT\"); // exact PositionSideOptional variant string","handlingStrategy":"validation","validationCode":"const POSITION_SIDE_OPTIONAL_VARIANTS = new Set([\"LONG\", \"SHORT\", \"FLAT_OR_UNKNOWN\"]);\nfunction toPositionSideOptional(raw) {\n  const v = raw == null || raw === \"\" ? \"FLAT_OR_UNKNOWN\" : raw;\n  if (!POSITION_SIDE_OPTIONAL_VARIANTS.has(v)) throw new Error(`unsupported PositionSideOptional: ${raw}`);\n  return v;\n}","typeGuard":"function isPositionSideOptional(v) { return v === 'LONG' || v === 'SHORT' || v === 'FLAT_OR_UNKNOWN'; }","tryCatchPattern":"Not applicable: panics become process aborts via abort_on_panic; no host-language catch is possible. Normalize direction strings and map empties to the none variant before calling.","preventionTips":["Map broker direction vocabulary ('long'/'short') to canonical LONG/SHORT strings.","Use the explicit none variant for neutral/unknown positions instead of empty strings.","Enforce exact case in configs and adapters.","Verify variant names against the crate version in binding tests."],"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"}