nautechsystems/nautilus_trader · error

invalid `TrailingOffsetTypeOptional` enum string value, was

Error message

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

What it means

`trailing_offset_type_from_cstr` parses a C string into `TrailingOffsetTypeOptional`, the optional-wrapped trailing offset type used at the FFI boundary. Any string not matching a variant (including the NOT_SET/None sentinel for the Optional type) panics inside `abort_on_panic`, aborting the process. Note the target type is the `Optional` wrapper, so plain `TrailingOffsetType` strings must still map to the Optional variant names.

Source

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

}

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

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

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Match the failing string against `TrailingOffsetTypeOptional` variant serializations and correct it.
  2. For 'no value', pass the Optional sentinel variant string (NOT_SET) rather than an empty or null string.
  3. Build the string via the paired `trailing_offset_type_to_cstr` to guarantee validity.
  4. Check the calling binding for stale constant tables after upgrading nautilus_model.

Example fix

// before
trailing_offset_type_from_cstr(str_to_cstr(""));
// after
trailing_offset_type_from_cstr(str_to_cstr("NOT_SET"));
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_trailing_offset_type_optional(s: &str) -> bool {
    TrailingOffsetTypeOptional::from_str(s).is_ok()
}

Type guard

fn as_trailing_offset_type(s: &str) -> Option<TrailingOffsetTypeOptional> {
    TrailingOffsetTypeOptional::from_str(s).ok()
}

Prevention

When it happens

Trigger: Calling `trailing_offset_type_from_cstr` with a raw `TrailingOffsetType` string or an empty string where the Optional "NOT_SET" sentinel is expected, or any misspelled value like "PRICE" vs "PRICE_TAKER".

Common situations: Adapters passing broker trailing-offset codes directly; forgetting that this FFI uses the Optional enum (empty string is not accepted as None); version drift where sentinel naming 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/be517a74e7a298d7. Report an issue: GitHub.