{"record":{"id":"f11b6cc28ae2b190","repo":"nautechsystems/nautilus_trader","slug":"invalid-value-for-make-price-was-value","errorCode":null,"errorMessage":"invalid `value` for make_price, was {value}","messagePattern":"invalid `value` for make_price, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/instruments/mod.rs","lineNumber":340,"sourceCode":"            value.round_dp_with_strategy(precision, RoundingStrategy::MidpointNearestEven);\n        Price::from_decimal_dp(rounded_decimal, self.price_precision()).map_err(Into::into)\n    }\n\n    /// # Panics\n    ///\n    /// Panics if the value cannot be converted to a `Price` (see `try_make_price_from_decimal`).\n    fn make_price_from_decimal(&self, value: Decimal) -> Price {\n        self.try_make_price_from_decimal(value).unwrap()\n    }\n\n    /// # Errors\n    ///\n    /// Returns an error if the value is not finite, not representable as a `Decimal`, or cannot\n    /// be converted to a `Price`.\n    #[inline(always)]\n    fn try_make_price(&self, value: f64) -> anyhow::Result<Price> {\n        let dec_value = Decimal::from_str(&value.to_string())\n            .map_err(|_| anyhow::anyhow!(\"invalid `value` for make_price, was {value}\"))?;\n        self.try_make_price_from_decimal(dec_value)\n    }\n\n    /// # Panics\n    ///\n    /// Panics if the value cannot be converted to a `Price` (see `try_make_price`).\n    fn make_price(&self, value: f64) -> Price {\n        self.try_make_price(value).unwrap()\n    }\n\n    /// Returns `price` rebuilt with the instrument precision when it is on the price grid.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error when `price` is a sentinel value or would require rounding.\n    #[inline(always)]\n    fn try_normalize_price(&self, price: Price) -> CorrectnessResult<Price> {\n        if price == ERROR_PRICE {","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/instruments/mod.rs#L322-L358","documentation":"Instrument::try_make_price converts an f64 to a Decimal via its string representation and then to a Price. If the f64 cannot be parsed into a Decimal (NaN, infinity, or a value Decimal cannot represent), this error is returned before any price-precision conversion happens.","triggerScenarios":"Calling instrument.make_price(f64::NAN), make_price(f64::INFINITY), or a value whose textual form Decimal::from_str rejects; also any path through make_price that forwards such values.","commonSituations":"Computing a price from an upstream indicator that yielded NaN (division by zero, empty data), propagating a sentinel infinite value from a calculation, or passing unset/optional values straight into make_price.","solutions":["Check value.is_finite() before calling make_price and handle NaN/infinity upstream.","Round/sanitize the computed value to a sane magnitude before conversion.","Prefer try_make_price (Result-returning) and map the error instead of panicking via make_price."],"exampleFix":"// before\nlet price = instrument.make_price(sma / len);\n// after\nlet raw = sma / len;\nanyhow::ensure!(raw.is_finite(), \"non-finite price computed\");\nlet price = instrument.make_price(raw);","handlingStrategy":"try-catch","validationCode":"if !value.is_finite() { return Err(TradeError::NonFinitePrice); }","typeGuard":null,"tryCatchPattern":"// Rust\nlet price = instrument\n    .try_make_price(value)\n    .map_err(|e| { log::warn!(\"price build failed: {e}\"); TradeError::BadPrice })?;","preventionTips":["Check is_finite() on every computed price before conversion","Never pass sentinel values (0/NaN defaults) straight into make_price","Prefer try_make_price over the panicking make_price in strategy code"],"tags":["price","decimal-conversion","nan","instrument"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}