nautechsystems/nautilus_trader · critical

invalid `OmsType` enum string value, was '{value}'

Error message

invalid `OmsType` enum string value, was '{value}'

What it means

oms_type_from_cstr converts a C string into an OmsType enum via FromStr. If the string matches no OmsType variant, the function panics with this message, and abort_on_panic converts the panic into a process abort at the FFI boundary. This guards against ever returning an undefined enum discriminant to C callers.

Source

Thrown at crates/model/src/ffi/enums.rs:624

pub extern "C" fn oms_type_to_cstr(value: OmsType) -> *const c_char {
    str_to_cstr(value.as_ref())
}

/// Returns an enum from a C string.
///
/// # Safety
///
/// Assumes `ptr` is a valid C string pointer.
///
/// # Panics
///
/// Panics if the C string does not correspond to a valid `OmsType` variant.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn oms_type_from_cstr(ptr: *const c_char) -> OmsType {
    abort_on_panic(|| {
        let value = unsafe { cstr_as_str(ptr) };
        OmsType::from_str(value)
            .unwrap_or_else(|_| panic!("invalid `OmsType` enum string value, was '{value}'"))
    })
}

#[unsafe(no_mangle)]
pub extern "C" fn option_kind_to_cstr(value: OptionKind) -> *const c_char {
    str_to_cstr(value.as_ref())
}

/// Returns an enum from a C string.
///
/// # Safety
///
/// Assumes `ptr` is a valid C string pointer.
///
/// # Panics
///
/// Panics if the C string does not correspond to a valid `OptionKind` variant.
#[unsafe(no_mangle)]

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use the exact OmsType variant string shown in the panic's '{value}' comparison — check the enum definition for accepted spellings (case-sensitive).
  2. Map config values to canonical variant names before calling the FFI function.
  3. Validate the string against the enumerated variant list in the host language.
  4. Fix buffer construction so the C string is exact and NUL-terminated (no whitespace or trailing bytes).
  5. Align crate versions between the caller and the library if variants were renamed.

Example fix

// before
oms_type_from_cstr("netting"); // panics: wrong case

// after
oms_type_from_cstr("Netting"); // exact OmsType variant string
Defensive patterns

Strategy: validation

Validate before calling

const OMS_TYPE_VARIANTS = new Set(["Netting", "Hedging"]);
if (typeof omsType !== "string" || !OMS_TYPE_VARIANTS.has(omsType)) {
  throw new Error(`unsupported OmsType: ${omsType}`);
}

Type guard

function isOmsType(v) { return typeof v === 'string' && OMS_TYPE_VARIANTS.has(v); }

Try / catch

Not applicable: the panic aborts the process; cannot be caught across FFI. Guard with pre-call validation.

Prevention

When it happens

Trigger: Calling oms_type_from_cstr(ptr) with a string that is not a valid OmsType variant, e.g. 'NETTING_GROSS', 'Hedging', '1', or an empty string. Valid values are only those accepted by OmsType::from_str (the variant names such as 'Netting', 'Hedging').

Common situations: Configuring an engine over FFI with an OMS type spelled differently than the Rust variant; passing a numeric config value where the string name is required; locale/case mistakes ('hedging' vs 'Hedging'); switching crate versions where the enum vocabulary changed.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/269db8ed367495c3. Report an issue: GitHub.