nautechsystems/nautilus_trader · critical

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

Error message

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

What it means

oto_trigger_mode_from_cstr converts a C string into an OtoTriggerMode enum via FromStr. Any string that does not match a variant triggers this panic, which abort_on_panic converts to a process abort at the FFI boundary. This prevents undefined enum values from crossing into Rust from C callers.

Source

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

pub extern "C" fn oto_trigger_mode_to_cstr(value: OtoTriggerMode) -> *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 `OtoTriggerMode` variant.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn oto_trigger_mode_from_cstr(ptr: *const c_char) -> OtoTriggerMode {
    abort_on_panic(|| {
        let value = unsafe { cstr_as_str(ptr) };
        OtoTriggerMode::from_str(value)
            .unwrap_or_else(|_| panic!("invalid `OtoTriggerMode` enum string value, was '{value}'"))
    })
}

#[unsafe(no_mangle)]
pub extern "C" fn order_side_to_cstr(value: OrderSideOptional) -> *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 `OrderSideOptional` variant.
#[unsafe(no_mangle)]

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use the exact OtoTriggerMode variant string; compare against the '{value}' in the panic and the enum's FromStr definition.
  2. Trim and normalize the incoming string in the host language before the FFI call.
  3. Validate against the known variant list before calling.
  4. Check case sensitivity — variant strings are matched exactly.
  5. Rebuild the caller against the same crate version if the enum was renamed.

Example fix

// before
oto_trigger_mode_from_cstr("OTO_ORDER"); // panics

// after
oto_trigger_mode_from_cstr("linked_or_least_one"); // exact variant string per enum definition
Defensive patterns

Strategy: validation

Validate before calling

const OTO_TRIGGER_MODE_VARIANTS = new Set(["linked_or_least_one"]);
if (typeof mode !== "string" || !OTO_TRIGGER_MODE_VARIANTS.has(mode)) {
  throw new Error(`unsupported OtoTriggerMode: ${mode}`);
}

Type guard

function isOtoTriggerMode(v) { return typeof v === 'string' && OTO_TRIGGER_MODE_VARIANTS.has(v); }

Try / catch

Not applicable: the panic becomes a process abort; no catch is possible. Validate the mode string before the FFI call.

Prevention

When it happens

Trigger: Calling oto_trigger_mode_from_cstr(ptr) with a string not accepted by OtoTriggerMode::from_str, e.g. 'ONE_TRIGGER_ONE', 'OTO_ORDER', an empty string, or a mis-terminated buffer. Only exact variant strings parse.

Common situations: Wiring contingent-order (OTO) configuration over FFI with hand-written mode strings; passing config values in the wrong case; a rename of the enum variant between versions so old callers pass stale names; whitespace picked up from config files.

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/13b137afbff0eeee. Report an issue: GitHub.