{"record":{"id":"0b15005c9250267e","repo":"nautechsystems/nautilus_trader","slug":"precision-from-scientific-should-return-some-in-st","errorCode":null,"errorMessage":"precision_from_scientific should return Some in strict mode","messagePattern":"precision_from_scientific should return Some in strict mode","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/src/string/parsing.rs","lineNumber":122,"sourceCode":"}\n\n/// Returns the decimal precision inferred from the given string.\n///\n/// For scientific notation (e.g., \"1e-300\", \"1.5e-2\"), the precision accounts\n/// for both the mantissa's fractional digits and the signed exponent:\n/// `max(0, fractional_digits - exponent)`, clamped to `u8::MAX` (255).\n///\n/// # Panics\n///\n/// Panics if the input string is malformed (e.g., \"1e-\" with no exponent value, or non-numeric\n/// exponents like \"1e-abc\").\n#[must_use]\npub fn precision_from_str(s: &str) -> u8 {\n    let s = s.trim().to_ascii_lowercase();\n\n    if s.contains('e') {\n        return precision_from_scientific(&s, false, true)\n            .expect(\"precision_from_scientific should return Some in strict mode\");\n    }\n\n    if let Some((_, decimal_part)) = s.split_once('.') {\n        clamp_precision_with_log(decimal_part.len(), \"Decimal\", &s)\n    } else {\n        0\n    }\n}\n\n/// Returns the minimum increment precision inferred from the given string,\n/// ignoring trailing zeros.\n///\n/// For scientific notation (e.g., \"1e-300\", \"1.5e-2\"), trailing zeros in the\n/// mantissa are stripped before computing precision, matching the behavior of\n/// [`precision_from_str`].\n#[must_use]\npub fn min_increment_precision_from_str(s: &str) -> u8 {\n    let s = s.trim().to_ascii_lowercase();","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/core/src/string/parsing.rs#L104-L140","documentation":"precision_from_str in crates/core/src/string/parsing.rs:122 computes decimal precision from a numeric string, and for strings containing 'e' it calls precision_from_scientific(&s, false, true) in strict mode, expecting Some. The expect panics with \"precision_from_scientific should return Some in strict mode\" when the scientific notation is so malformed that even strict parsing cannot extract an exponent (e.g. 'e' present but no numeric exponent follows).","triggerScenarios":"Calling precision_from_str with strings like \"1e\", \"2.5e+\", \"e-\", or \"1.0Eexponent\" — the 'e' check passes but scientific parsing cannot recover an exponent, so strict mode returns None and the expect fires.","commonSituations":"Config files or CSV feeds with truncated exponent fields (\"1e\" after a spreadsheet cut a column); regex-based string munging that dropped the exponent digits; hand-typed precision values.","solutions":["Fix the input to well-formed scientific notation, e.g. \"1.5e-8\" instead of \"1e\" or \"2.5e+\".","Pre-validate with a regex such as ^-?\\d+(\\.\\d+)?[eE][+-]?\\d+$ before calling precision_from_str.","Correct the upstream producer (vendor feed, config generator) that emitted the truncated notation.","If malformed values are expected in your pipeline, sanitize or reject them before this call rather than letting the strict-mode expect fire."],"exampleFix":"// before\nlet p = precision_from_str(\"2.5e+\");   // panics in strict mode\n// after\nlet p = precision_from_str(\"2.5e-9\");  // well-formed scientific notation","handlingStrategy":"validation","validationCode":"import re\nif 'e' in s.lower():\n    assert re.fullmatch(r\"\\d+(\\.\\d+)?e[+-]?\\d+\", s.lower()), f\"malformed scientific notation: {s!r}\"\nprecision = precision_from_str(s)","typeGuard":"fn is_parseable_numeric(s: &str) -> bool {\n    s.trim().parse::<f64>().is_ok()\n}","tryCatchPattern":null,"preventionTips":["Regex-validate scientific notation before calling precision_from_str.","Fix truncated exponents at the producing config/feed, not at the call site.","Add fixture tests with 'e', 'e-', 'e+' edge inputs to your pipeline tests."],"tags":["parsing","scientific-notation","precision","panic"],"backgroundTag":"invalid-argument-format","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"}