nautechsystems/nautilus_trader · critical

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

Error message

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

What it means

market_status_action_from_cstr converts a C string into a MarketStatusAction enum via FromStr. On an unrecognized string the function panics with this message; abort_on_panic turns the panic into a process abort so it never unwinds across the C ABI. The library prefers aborting over returning a partial/undefined enum value to FFI callers.

Source

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

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

#[unsafe(no_mangle)]
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.

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the offending '{value}' in the panic message and correct it to an exact MarketStatusAction variant string (see the enum's FromStr/as_ref definitions).
  2. Normalize/map feed or config strings to valid variant names in the caller before the FFI call.
  3. Validate the string against the known variant list in the host language before calling.
  4. Rebuild/reinstall so calling code and the Rust crate use the same version with matching variant names.
  5. Ensure the C string is correctly NUL-terminated and contains no stray whitespace or garbage.

Example fix

// before
market_status_action_from_cstr("halted"); // panics

// after
market_status_action_from_cstr("halt"); // exact MarketStatusAction variant string
Defensive patterns

Strategy: validation

Validate before calling

const MARKET_STATUS_ACTION_VARIANTS = new Set(["open", "pause", "resume", "close"]);
if (typeof value !== "string" || !MARKET_STATUS_ACTION_VARIANTS.has(value)) {
  throw new Error(`unsupported MarketStatusAction: ${value}`);
}

Type guard

function isMarketStatusAction(v) { return typeof v === 'string' && MARKET_STATUS_ACTION_VARIANTS.has(v); }

Try / catch

Not applicable: panic becomes a process abort via abort_on_panic and cannot be caught. Validate inputs before the FFI call.

Prevention

When it happens

Trigger: Calling market_status_action_from_cstr(ptr) with a string that is not a MarketStatusAction variant, e.g. 'PAUSE', 'halt', 'RESUME_TRADING', an empty string, or a buffer with trailing NUL/garbage bytes. Only strings matching the enum's FromStr impl are accepted.

Common situations: Translating an exchange's market-status action vocabulary (e.g. 'trading_pause') directly without mapping; passing a Python enum repr instead of its value; a version change where a MarketStatusAction variant was renamed so previously valid strings no longer parse; buffer/length mistakes when preparing the C string.

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/1a87cfbb58c78280. Report an issue: GitHub.