nautechsystems/nautilus_trader · critical
invalid `OrderStatus` enum string value, was '{value}'
Error message
invalid `OrderStatus` enum string value, was '{value}' What it means
order_status_from_cstr converts a C string into an OrderStatus 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 so no undefined status value crosses the ABI.
Source
Thrown at crates/model/src/ffi/enums.rs:717
pub extern "C" fn order_status_to_cstr(value: OrderStatus) -> *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 `OrderStatus` variant.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn order_status_from_cstr(ptr: *const c_char) -> OrderStatus {
abort_on_panic(|| {
let value = unsafe { cstr_as_str(ptr) };
OrderStatus::from_str(value)
.unwrap_or_else(|_| panic!("invalid `OrderStatus` enum string value, was '{value}'"))
})
}
#[unsafe(no_mangle)]
pub extern "C" fn order_type_to_cstr(value: OrderType) -> *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 `OrderType` variant.
#[unsafe(no_mangle)]View on GitHub (pinned to 18893faf8b)
Solutions
- Compare the '{value}' in the panic with the valid OrderStatus variant strings and pass the exact one.
- Add an explicit venue-to-Nautilus status mapping for external feed/broker strings.
- Whitelist-validate the string in the host language before calling the FFI function.
- Trim whitespace and confirm correct NUL-termination of the C string.
- Rebuild against the current crate version if statuses were renamed or added.
Example fix
// before
order_status_from_cstr("cancelled"); // panics: wrong spelling/case
// after
order_status_from_cstr("Canceled"); // exact OrderStatus variant string Defensive patterns
Strategy: validation
Validate before calling
const STATUS_MAP = { partially_filled: "PartiallyFilled", cancelled: "Canceled", open: "Submitted" };
const canonical = STATUS_MAP[raw] ?? raw;
const ORDER_STATUS_VARIANTS = new Set(["Initialized", "Submitted", "Accepted", "Rejected", "Canceled", "Expired", "Filled", "PartiallyFilled"]);
if (!ORDER_STATUS_VARIANTS.has(canonical)) throw new Error(`unsupported OrderStatus: ${raw}`); Type guard
function isOrderStatus(v) { return typeof v === 'string' && ORDER_STATUS_VARIANTS.has(v); } Try / catch
Not applicable: abort_on_panic converts the panic into a process abort; try/catch cannot intercept it. Validate/translate status strings before the call.
Prevention
- Maintain an explicit venue-status to OrderStatus mapping and cover it with tests.
- Never pass raw broker status strings across FFI.
- Watch spelling/case differences like cancelled vs Canceled.
- Diff enum variants against the previous version when upgrading.
When it happens
Trigger: Calling order_status_from_cstr(ptr) with a string not accepted by OrderStatus::from_str, e.g. 'FILLED_PARTIAL', 'Open', 'Canceled' (wrong spelling relative to the enum), an empty string, or a buffer with trailing garbage. Only exact variant strings parse.
Common situations: Translating venue order-status vocabulary ('partially_filled', 'cancelled' vs 'CANCELED') directly into the FFI call; replaying persisted events recorded under an older enum vocabulary; passing a Python enum repr; case mismatches.
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
- invalid `AggressorSide` enum string value, was '{value}'
- invalid `AssetClass` enum string value, was '{value}'
- invalid `InstrumentClass` enum string value, was '{value}'
- invalid `BarAggregation` enum string value, was '{value}'
- invalid `BookAction` enum string value, was '{value}'
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/e8f59a573d0fcf35.
Report an issue: GitHub.