{"record":{"id":"516535fe965e0c5d","repo":"nautechsystems/nautilus_trader","slug":"price-overflow-price-raw-exceeds-priceraw-range","errorCode":null,"errorMessage":"Price overflow: {price_raw} exceeds PriceRaw range","messagePattern":"Price overflow: (.+?) exceeds PriceRaw range","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/defi/tick_map/sqrt_price_math.rs","lineNumber":450,"sourceCode":"            divisor_base,\n            &[fixed_scalar, decimal_adjustment],\n        )?\n    } else {\n        FullMath::mul_div_scaled(sqrt_price, sqrt_price, divisor_base, &[fixed_scalar])?\n            / decimal_adjustment\n    };\n\n    price_from_u256(price_raw)\n}\n\npub(crate) fn price_from_u256(price_raw: U256) -> anyhow::Result<Price> {\n    anyhow::ensure!(\n        price_raw <= U256::from(PRICE_RAW_MAX as u128),\n        \"Price overflow: {price_raw} exceeds maximum valid raw price {PRICE_RAW_MAX}\"\n    );\n    let price_raw: i128 = price_raw\n        .try_into()\n        .map_err(|_| anyhow::anyhow!(\"Price overflow: {price_raw} exceeds PriceRaw range\"))?;\n\n    Price::from_raw_checked(price_raw, FIXED_PRECISION).map_err(Into::into)\n}\n\n#[cfg(test)]\nmod tests {\n    // Most of the tests are based on https://github.com/Uniswap/v3-core/blob/main/test/SqrtPriceMath.spec.ts\n    use rstest::*;\n\n    use super::*;\n    use crate::defi::tick_map::{\n        full_math::{DECIMAL_EXPONENT_MAX, Q96_U160},\n        tick_math::MAX_SQRT_RATIO,\n    };\n\n    #[rstest]\n    #[should_panic(expected = \"sqrt_price_x96 must be greater than zero\")]\n    fn test_if_get_next_sqrt_price_from_input_panic_if_price_zero() {","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/defi/tick_map/sqrt_price_math.rs#L432-L468","documentation":"price_from_u256 casts the validated raw price into an i128 (PriceRaw) before constructing the Price. This error is a defensive fallback thrown if the U256 value cannot fit into i128 despite passing the PRICE_RAW_MAX check — an internal invariant guard protecting Price::from_raw_checked from out-of-range input.","triggerScenarios":"Practically unreachable via the public API because the preceding PRICE_RAW_MAX ensure() rejects values above PRICE_RAW_MAX first; it can only fire if PRICE_RAW_MAX itself exceeds i128 range or the check and cast diverge (version change in constants).","commonSituations":"Custom forks or modified builds where PRICE_RAW_MAX was changed; unexpected library version changes altering constant definitions.","solutions":["Do not attempt to work around it; if hit, file an issue — it indicates an internal constant inconsistency.","Verify your nautilus_model version constants (PRICE_RAW_MAX vs PriceRaw/i128 range) are consistent.","Update to the latest release where the invariant holds."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Practically unreachable; treat as a bug report if seen\nlet price = price_from_u256(raw).map_err(|e| {\n    if e.to_string().contains(\"PriceRaw range\") {\n        anyhow::anyhow!(\"internal error: PRICE_RAW_MAX inconsistent with PriceRaw: {e}\")\n    } else { e }\n});","preventionTips":["Keep PRICE_RAW_MAX and the PriceRaw (i128) type in sync when upgrading","Do not modify library constants; report inconsistencies upstream"],"tags":["rust","internal","price","invariant"],"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"}