nautechsystems/nautilus_trader · critical

{msg}: {e}

Error message

{msg}: {e}

What it means

`CorrectnessResultExt::expect_display` unwraps a `CorrectnessResult` and panics with the error's human-readable `Display` form prefixed by the caller's message (`{msg}: {e}`), unlike `Result::expect` which uses the `Debug` format and leaks internal struct layout. The panic itself means a correctness check in NautilusTrader's domain logic failed — e.g. a predicate violation, missing set member, or invalid value — at a point the code assumed was impossible. The meaningful message is the `msg` plus the `CorrectnessError` display text at the panic site.

Source

Thrown at crates/core/src/correctness.rs:231

///
/// Use this instead of [`std::result::Result::expect`] when unwrapping a
/// correctness result: `expect` formats the error with `{:?}`, which exposes
/// the internal [`CorrectnessError`] struct layout in panic output, while
/// [`CorrectnessResultExt::expect_display`] preserves the human-readable
/// message defined on each variant.
pub trait CorrectnessResultExt<T> {
    /// Returns the contained [`Ok`] value, panicking with `msg: <error display>`
    /// on [`Err`].
    fn expect_display(self, msg: &str) -> T;
}

impl<T> CorrectnessResultExt<T> for CorrectnessResult<T> {
    #[inline]
    #[track_caller]
    fn expect_display(self, msg: &str) -> T {
        match self {
            Ok(value) => value,
            Err(e) => panic!("{msg}: {e}"),
        }
    }
}

/// Checks the `predicate` is true.
///
/// # Errors
///
/// Returns an error if the validation check fails.
#[inline(always)]
pub fn check_predicate_true(predicate: bool, fail_msg: &str) -> Result<()> {
    if !predicate {
        return Err(CorrectnessError::PredicateViolation {
            message: fail_msg.to_string(),
        });
    }
    Ok(())
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the `{msg}: {e}` panic message; the `CorrectnessError` display names the exact violated check.
  2. Fix the caller to satisfy the invariant before calling the checked API (e.g. validate price precision, ensure set membership).
  3. Use the fallible correctness API (`Result`-returning functions) and handle the error instead of `expect_display` where recovery is possible.
  4. If the invariant looks valid, check for adapter data-cleaning issues (NaNs, wrong precision) feeding the check.

Example fix

// before
let ts_event = checked_ts.expect_display("timestamp must be ordered");
// after
let ts_event = match checked_ts {
    Ok(ts) => ts,
    Err(e) => { log::error!("correctness: {e}"); return Err(e.into()); }
};
Defensive patterns

Strategy: try-catch

Validate before calling

// Prefer the fallible correctness APIs before reaching expect_display
if let Err(e) = correctness::check_predicate_true(cond, "expected condition") {
    log::error!("correctness violation: {e}");
    return Err(e.into());
}

Try / catch

// Rust panics are not catchable with try/catch; convert to Result at the boundary
let value = result.map_err(|e| { log::error!("{msg}: {e}"); e })?;
// only use expect_display where failure is truly unrecoverable

Prevention

When it happens

Trigger: Any `result.expect_display("context")` call on a correctness check that returns `Err` — e.g. `check_predicate_true` failing, a required set member missing, or an out-of-range value found during invariant verification.

Common situations: Market data or order state violating an assumed invariant (e.g. price precision mismatch); calling code passing data from an external adapter that the correctness layer rejects; regressions after upgrading where validation tightened.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/8951d43fed7a33cb. Report an issue: GitHub.