{"record":{"id":"efc9f1b31ed810cd","repo":"nautechsystems/nautilus_trader","slug":"raw-value-exceeds-moneyraw-range-in-money-from-ma","errorCode":null,"errorMessage":"Raw value exceeds MoneyRaw range in Money::from_mantissa_exponent","messagePattern":"Raw value exceeds MoneyRaw range in Money::from_mantissa_exponent","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/types/money.rs","lineNumber":289,"sourceCode":"    #[must_use]\n    pub fn from_mantissa_exponent(mantissa: i64, exponent: i8, currency: Currency) -> Self {\n        check_fixed_precision(currency.precision).expect_display(FAILED);\n\n        if mantissa == 0 {\n            return Self { raw: 0, currency };\n        }\n\n        let raw_i128 =\n            mantissa_exponent_to_fixed_i128(i128::from(mantissa), exponent, currency.precision)\n                .expect(\"Overflow in Money::from_mantissa_exponent\");\n\n        #[allow(\n            clippy::useless_conversion,\n            reason = \"i128 to MoneyRaw is real when not high-precision\"\n        )]\n        let raw: MoneyRaw = raw_i128\n            .try_into()\n            .expect(\"Raw value exceeds MoneyRaw range in Money::from_mantissa_exponent\");\n        assert!(\n            raw >= MONEY_RAW_MIN && raw <= MONEY_RAW_MAX,\n            \"`raw` value {raw} exceeded bounds [{MONEY_RAW_MIN}, {MONEY_RAW_MAX}] for Money\"\n        );\n\n        Self { raw, currency }\n    }\n\n    /// Creates a new [`Money`] instance with a value of zero with the given [`Currency`].\n    ///\n    /// # Panics\n    ///\n    /// Panics if `currency.precision` exceeds the maximum allowed by `check_fixed_precision`.\n    #[must_use]\n    pub fn zero(currency: Currency) -> Self {\n        check_fixed_precision(currency.precision).expect_display(FAILED);\n        Self { raw: 0, currency }\n    }","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/types/money.rs#L271-L307","documentation":"After computing the fixed-point i128 raw value, Money::from_mantissa_exponent converts it into MoneyRaw via try_into and panics with this message if the value falls outside the MoneyRaw range. The following assert re-checks MONEY_RAW_MIN/MAX bounds. This is a secondary range guard distinct from the i128 arithmetic overflow check.","triggerScenarios":"Money::from_mantissa_exponent with a mantissa/exponent pair whose i128 result is valid but exceeds MONEY_RAW_MAX (relevant in non-high-precision builds where MoneyRaw is narrower than i128).","commonSituations":"Non-high-precision builds handling amounts beyond the narrower raw type's range; loading historical or synthetic datasets with extreme amounts; currency configured with wrong precision amplifying the magnitude.","solutions":["Check the amount against MONEY_RAW_MAX/MIN (or the currency's max Money) before constructing.","Compile with the high-precision feature so MoneyRaw is i128 and cannot hit this narrowing failure.","Split or rescale the amount (different currency units) to fit the representable range."],"exampleFix":"// before\nlet m = Money::from_mantissa_exponent(mantissa, exponent, currency); // panics if raw > MONEY_RAW_MAX\n// after\nif mantissa.abs() > (MONEY_RAW_MAX as i128 / scale_for(exponent, currency.precision)) {\n    return Err(...);\n}\nlet m = Money::from_mantissa_exponent(mantissa, exponent, currency);","handlingStrategy":"validation","validationCode":"if amount_abs > MONEY_RAW_MAX_scaled_for(currency) {\n    return Err(\"amount exceeds MoneyRaw range for currency precision\");\n}\nlet m = Money::from_mantissa_exponent(mantissa, exponent, currency);","typeGuard":"fn in_money_range(raw_i128: i128) -> bool {\n    raw_i128 >= MONEY_RAW_MIN as i128 && raw_i128 <= MONEY_RAW_MAX as i128\n}","tryCatchPattern":null,"preventionTips":["Use the high-precision build when amounts can approach i64 limits.","Validate currency precision configuration — wrong precision inflates the raw magnitude.","Cap aggregate amounts at a domain-level maximum."],"tags":["rust","overflow","money","range-check"],"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"}