nautechsystems/nautilus_trader · critical
invalid `LiquiditySide` enum string value, was '{value}'
Error message
invalid `LiquiditySide` enum string value, was '{value}' What it means
`liquidity_side_from_cstr` parses a C string into the Rust `LiquiditySide` enum (e.g. MAKER/TAKER) and panics if the string is not a recognized variant. Because the function is exported across the C FFI, the panic is converted by `abort_on_panic` into a process abort instead of unwinding into foreign code. Only exact canonical strings from `liquidity_side_to_cstr` are accepted.
Source
Thrown at crates/model/src/ffi/enums.rs:554
pub extern "C" fn liquidity_side_to_cstr(value: LiquiditySide) -> *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 `LiquiditySide` variant.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn liquidity_side_from_cstr(ptr: *const c_char) -> LiquiditySide {
abort_on_panic(|| {
let value = unsafe { cstr_as_str(ptr) };
LiquiditySide::from_str(value)
.unwrap_or_else(|_| panic!("invalid `LiquiditySide` enum string value, was '{value}'"))
})
}
#[unsafe(no_mangle)]
pub extern "C" fn market_status_to_cstr(value: MarketStatus) -> *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 `MarketStatus` variant.
#[unsafe(no_mangle)]View on GitHub (pinned to 18893faf8b)
Solutions
- Log the exact string and diff against the canonical `LiquiditySide` variant spellings.
- Map venue liquidity indicators explicitly to `LiquiditySide` strings at the adapter boundary.
- Normalize case and trim whitespace before calling; the match is exact.
- Generate strings via `liquidity_side_to_cstr` from enum values rather than literals.
- Validate the string against the accepted set before the FFI call, since invalid input aborts the process.
Example fix
// before liq = "M" liquidity_side_from_cstr(liq.encode()) // after liq = "MAKER" # canonical LiquiditySide spelling liquidity_side_from_cstr(liq.encode())
Defensive patterns
Strategy: validation
Validate before calling
VALID_LIQUIDITY_SIDES = {"NO_LIQUIDITY_SIDE", "MAKER", "TAKER"} # verify against LiquiditySide definition
assert liq_str in VALID_LIQUIDITY_SIDES, f"bad LiquiditySide: {liq_str!r}"
liquidity_side_from_cstr(liq_str.encode()) Type guard
def is_valid_liquidity_side(s: str) -> bool:
return s in VALID_LIQUIDITY_SIDES # canonical strings from LiquiditySide::as_ref Prevention
- Map exchange liquidity indicators (e.g. 'M'/'T') to LiquiditySide strings explicitly.
- Normalize case before the FFI call.
- Validate against the canonical set before calling; failure aborts the process.
- Generate strings via liquidity_side_to_cstr from enum values.
- Round-trip test hard-coded strings in CI and after upgrades.
When it happens
Trigger: Calling `liquidity_side_from_cstr(ptr)` with strings like 'maker'/'taker' in wrong case, short codes like 'M', an empty string, or a value taken from an exchange's liquidity indicator that differs from the canonical enum spelling.
Common situations: Parsing execution/position reports in adapters where venue liquidity flags must be mapped to `LiquiditySide`; typos in adapter code; case normalization mistakes; serialization changes between versions.
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/993d9f7b03a71b63.
Report an issue: GitHub.