{"record":{"id":"88ce32d1bb8c479a","repo":"nautechsystems/nautilus_trader","slug":"raw-value-exceeds-priceraw-range-in-price-from-ma","errorCode":null,"errorMessage":"Raw value exceeds PriceRaw range in Price::from_mantissa_exponent","messagePattern":"Raw value exceeds PriceRaw range in Price::from_mantissa_exponent","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/model/src/types/price.rs","lineNumber":533,"sourceCode":"    /// Panics if the resulting raw value exceeds [`PRICE_RAW_MAX`] or [`PRICE_RAW_MIN`].\n    #[must_use]\n    pub fn from_mantissa_exponent(mantissa: i64, exponent: i8, precision: u8) -> Self {\n        check_fixed_precision(precision).expect_display(FAILED);\n\n        if mantissa == 0 {\n            return Self { raw: 0, precision };\n        }\n\n        let raw_i128 = mantissa_exponent_to_fixed_i128(i128::from(mantissa), exponent, precision)\n            .expect(\"Overflow in Price::from_mantissa_exponent\");\n\n        #[allow(\n            clippy::useless_conversion,\n            reason = \"i128 to PriceRaw is real when not high-precision\"\n        )]\n        let raw: PriceRaw = raw_i128\n            .try_into()\n            .expect(\"Raw value exceeds PriceRaw range in Price::from_mantissa_exponent\");\n        assert!(\n            raw >= PRICE_RAW_MIN && raw <= PRICE_RAW_MAX,\n            \"`raw` value {raw} exceeded bounds [{PRICE_RAW_MIN}, {PRICE_RAW_MAX}] for Price\"\n        );\n\n        Self { raw, precision }\n    }\n\n    /// Checked variant of [`Price::from_mantissa_exponent`].\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the precision is invalid or the resulting raw value\n    /// exceeds the `PriceRaw` bounds.\n    pub fn from_mantissa_exponent_checked(\n        mantissa: i64,\n        exponent: i8,\n        precision: u8,","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/types/price.rs#L515-L551","documentation":"After a successful i128 conversion, from_mantissa_exponent narrows the i128 raw value to PriceRaw (the platform's price storage integer). If the i128 value does not fit in PriceRaw, try_into().expect panics. This is a narrower-range overflow than the i128 overflow error: the value fits i128 but exceeds PriceRaw's bounds, which the following assert also documents.","triggerScenarios":"Price::from_mantissa_exponent with mantissa/exponent whose fixed-point raw value fits i128 but is greater than PRICE_RAW_MAX (or below PRICE_RAW_MIN), typically huge mantissas with large positive exponents under a non-high-precision PriceRaw build.","commonSituations":"Loading prices from a venue denominated in minimal units with a large exponent mismatch; config mistakes where precision is lower than needed, inflating the fixed-point raw; unit tests reusing quantity-scale numbers as prices.","solutions":["Lower the effective value or raise precision so the fixed-point raw falls within [PRICE_RAW_MIN, PRICE_RAW_MAX].","Check PRICE_RAW_MAX before constructing and reject/clamp the offending tick instead of constructing.","Use the high-precision feature/build so PriceRaw is wider if your instrument range legitimately needs it.","Sanitize upstream data: reject prices beyond the instrument's defined price bounds before conversion."],"exampleFix":"// before\nlet price = Price::from_mantissa_exponent(i64::MAX, 20, 9); // raw exceeds PriceRaw range\n// after\nlet price = Price::from_mantissa_exponent(12_345, 5, 9); // 1,234,500,000,000,000 fits PriceRaw","handlingStrategy":"validation","validationCode":"// Rust\nfn price_raw_fits(raw: i128) -> bool {\n    raw >= i128::from(PRICE_RAW_MIN) && raw <= i128::from(PRICE_RAW_MAX)\n}","typeGuard":"fn to_price_raw(raw: i128) -> Option<PriceRaw> {\n    PriceRaw::try_from(raw).ok().filter(|r| (PRICE_RAW_MIN..=PRICE_RAW_MAX).contains(r))\n}","tryCatchPattern":null,"preventionTips":["Know PRICE_RAW_MAX for your build (high-precision vs default) and validate against it.","Reject prices outside the instrument's min/max price at ingestion.","Avoid reusing quantity-scale constants as prices in tests and fixtures.","Prefer constructing Price from Decimal with explicit precision rather than raw mantissa/exponent math."],"tags":["rust","arithmetic-overflow","panic","price"],"backgroundTag":"value-out-of-range","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"}