{"record":{"id":"8951d43fed7a33cb","repo":"nautechsystems/nautilus_trader","slug":"msg-e","errorCode":null,"errorMessage":"{msg}: {e}","messagePattern":"\\{msg\\}: \\{e\\}","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/core/src/correctness.rs","lineNumber":231,"sourceCode":"///\n/// Use this instead of [`std::result::Result::expect`] when unwrapping a\n/// correctness result: `expect` formats the error with `{:?}`, which exposes\n/// the internal [`CorrectnessError`] struct layout in panic output, while\n/// [`CorrectnessResultExt::expect_display`] preserves the human-readable\n/// message defined on each variant.\npub trait CorrectnessResultExt<T> {\n    /// Returns the contained [`Ok`] value, panicking with `msg: <error display>`\n    /// on [`Err`].\n    fn expect_display(self, msg: &str) -> T;\n}\n\nimpl<T> CorrectnessResultExt<T> for CorrectnessResult<T> {\n    #[inline]\n    #[track_caller]\n    fn expect_display(self, msg: &str) -> T {\n        match self {\n            Ok(value) => value,\n            Err(e) => panic!(\"{msg}: {e}\"),\n        }\n    }\n}\n\n/// Checks the `predicate` is true.\n///\n/// # Errors\n///\n/// Returns an error if the validation check fails.\n#[inline(always)]\npub fn check_predicate_true(predicate: bool, fail_msg: &str) -> Result<()> {\n    if !predicate {\n        return Err(CorrectnessError::PredicateViolation {\n            message: fail_msg.to_string(),\n        });\n    }\n    Ok(())\n}","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/core/src/correctness.rs#L213-L249","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the `{msg}: {e}` panic message; the `CorrectnessError` display names the exact violated check.","Fix the caller to satisfy the invariant before calling the checked API (e.g. validate price precision, ensure set membership).","Use the fallible correctness API (`Result`-returning functions) and handle the error instead of `expect_display` where recovery is possible.","If the invariant looks valid, check for adapter data-cleaning issues (NaNs, wrong precision) feeding the check."],"exampleFix":"// before\nlet ts_event = checked_ts.expect_display(\"timestamp must be ordered\");\n// after\nlet ts_event = match checked_ts {\n    Ok(ts) => ts,\n    Err(e) => { log::error!(\"correctness: {e}\"); return Err(e.into()); }\n};","handlingStrategy":"try-catch","validationCode":"// Prefer the fallible correctness APIs before reaching expect_display\nif let Err(e) = correctness::check_predicate_true(cond, \"expected condition\") {\n    log::error!(\"correctness violation: {e}\");\n    return Err(e.into());\n}","typeGuard":null,"tryCatchPattern":"// Rust panics are not catchable with try/catch; convert to Result at the boundary\nlet value = result.map_err(|e| { log::error!(\"{msg}: {e}\"); e })?;\n// only use expect_display where failure is truly unrecoverable","preventionTips":["Reserve `expect_display` for genuinely unrecoverable invariant failures","Prefer `Result`-returning correctness checks in adapter/IO-facing code","Log the display message, which names the exact violated check, to diagnose quickly","Validate external data (prices, timestamps, IDs) before passing to correctness-checked APIs"],"tags":["rust","panic","invariants","correctness"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}