{"record":{"id":"20c5e467d45840c7","repo":"nautechsystems/nautilus_trader","slug":"precision-exceeded-i8-range","errorCode":null,"errorMessage":"precision exceeded i8 range","messagePattern":"precision exceeded i8 range","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/decode/primitives.rs","lineNumber":301,"sourceCode":"    }\n    9 - trailing\n}\n\n/// Decodes a minimum price increment from the given value, expressed in units of 1e-9.\n///\n/// The precision is derived from the actual tick value to avoid truncation of\n/// fractional tick sizes (e.g., treasury futures with 1/256 or 1/32 ticks).\n/// The derived precision is floored at `precision` (typically the currency precision).\n///\n/// # Panics\n///\n/// Panics if `precision` exceeds the supported `Price` precision.\n#[inline(always)]\n#[must_use]\npub fn decode_price_increment(value: i64, precision: u8) -> Price {\n    match value {\n        0 | i64::MAX => {\n            let exponent = i8::try_from(precision).expect(\"precision exceeded i8 range\");\n            Price::from_mantissa_exponent(1, -exponent, precision)\n        }\n        _ => {\n            let derived = precision_from_raw(value).max(precision);\n            Price::from_raw(decode_raw_price_i64(value), derived)\n        }\n    }\n}\n\n/// Decodes a quantity from the given value, expressed in standard whole-number units.\n#[inline(always)]\n#[must_use]\npub fn decode_quantity(value: u64) -> Quantity {\n    quantity_from_whole(value)\n}\n\n/// Decodes a quantity from the given optional value, where `i64::MAX` indicates missing data.\n///","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/decode/primitives.rs#L283-L319","documentation":"`decode_price_increment` converts a Databento price-increment raw value into a `Price`. The `precision: u8` parameter must fit in `i8` because it is negated into the price exponent; the `.expect` panics when precision exceeds 127. This can only happen with absurd precision values not produced by any real instrument definition.","triggerScenarios":"Calling `decode_price_increment` (directly or via `decode_currency_pair`/`decode_equity`/`decode_futures_contract`/etc.) with a precision greater than 127, typically from a raw instrument definition whose `raw_tick`/denominator math overflowed or was computed incorrectly.","commonSituations":"Custom/incorrect Symbology or instrument-definition data from Databento, a hand-rolled decoder passing raw exponent bytes as precision, or a regression in `precision_from_raw` producing garbage values.","solutions":["Validate the instrument definition's precision before decoding (clamp or reject precision > 127).","Check that the tick size / denominator conversion feeding `precision` is correct for the dataset.","If decoding third-party definitions, sanitize: use `precision.min(127)` or return a decode error instead of panicking."],"exampleFix":"// before\nlet price = decode_price_increment(raw_tick, precision_u8);\n// after\nassert!(precision_u8 <= i8::MAX as u8, \"unsupported precision {precision_u8}\");\nlet price = decode_price_increment(raw_tick, precision_u8);","handlingStrategy":"validation","validationCode":"if precision_u8 > i8::MAX as u8 {\n    return Err(format!(\"unsupported precision {precision_u8}\"));\n}\nlet price = decode_price_increment(raw_tick, precision_u8);","typeGuard":"fn precision_ok(p: u8) -> bool { p <= i8::MAX as u8 }","tryCatchPattern":null,"preventionTips":["Validate instrument-definition precision before decoding.","Sanitize third-party or custom definitions before feeding the decoder.","Check tick-size denominator math when building precision from raw values."],"tags":["rust","panic","precision","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"}