{"record":{"id":"9300a560fd5f1db5","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-string-value-into-unixnanos","errorCode":null,"errorMessage":"Failed to parse string '{value}' into UnixNanos: {e}. Use str::parse() for non-panicking error handling.","messagePattern":"Failed to parse string '(.+?)' into UnixNanos: (.+?)\\. Use str::parse\\(\\) for non-panicking error handling\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/src/nanos.rs","lineNumber":888,"sourceCode":"        value.0\n    }\n}\n\n/// Converts a string slice to [`UnixNanos`].\n///\n/// # Panics\n///\n/// This implementation will panic if the string cannot be parsed into a valid [`UnixNanos`].\n/// This is intentional fail-fast behavior where invalid timestamps indicate a critical\n/// logic error that should halt execution rather than silently propagate incorrect data.\n///\n/// For error handling without panicking, use [`str::parse::<UnixNanos>()`] which returns\n/// a [`Result`].\nimpl From<&str> for UnixNanos {\n    fn from(value: &str) -> Self {\n        value\n            .parse()\n            .unwrap_or_else(|e| panic!(\"Failed to parse string '{value}' into UnixNanos: {e}. Use str::parse() for non-panicking error handling.\"))\n    }\n}\n\n/// Converts a [`String`] to [`UnixNanos`].\n///\n/// # Panics\n///\n/// This implementation will panic if the string cannot be parsed into a valid [`UnixNanos`].\n/// This is intentional fail-fast behavior where invalid timestamps indicate a critical\n/// logic error that should halt execution rather than silently propagate incorrect data.\n///\n/// For error handling without panicking, use [`str::parse::<UnixNanos>()`] which returns\n/// a [`Result`].\nimpl From<String> for UnixNanos {\n    fn from(value: String) -> Self {\n        value\n            .parse()\n            .unwrap_or_else(|e| panic!(\"Failed to parse string '{value}' into UnixNanos: {e}. Use str::parse() for non-panicking error handling.\"))","sourceCodeStart":870,"sourceCodeEnd":906,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/core/src/nanos.rs#L870-L906","documentation":"`impl From<&str> for UnixNanos` parses the string as a u64 nanosecond value and panics on any parse failure. The panic message explicitly points to the intended non-panicking alternative: `str::parse::<UnixNanos>()`, which returns a Result. This error is thrown for malformed or out-of-range strings such as non-numeric text, negative numbers, or values exceeding u64::MAX.","triggerScenarios":"Calling `UnixNanos::from(\"abc\")`, `UnixNanos::from(\"-1\")` (negative is invalid for u64), `UnixNanos::from(\"99999999999999999999999\")` (exceeds u64::MAX), or any string with whitespace/units (e.g. \"123ns\", \"1.5\"). Also `\"abc\".into()` / `\"abc\".to_string().into()` conversion sites.","commonSituations":"Reading timestamps from environment variables, CLI args, config files, or CSV/JSON payloads where the field may be empty, contain a units suffix, be a float, or be negative; log-parsing code feeding raw tokens into UnixNanos::from.","solutions":["Use `value.parse::<UnixNanos>()` (or `parse::<u64>()`) and handle the Err instead of the panicking `From` impl.","Pre-validate the string: trim, ensure it is all ASCII digits and fits in u64 before conversion.","Handle common formats upstream: strip units, reject/persist floats by converting with explicit precision, check for a leading '-'.","If the input may legitimately be absent, return Option/Result from your wrapper rather than calling From at all."],"exampleFix":"// before\nlet ts = UnixNanos::from(raw_field); // panics on bad input\n\n// after\nlet ts: UnixNanos = raw_field.trim().parse().map_err(|e| {\n    anyhow!(\"invalid UnixNanos field '{raw_field}': {e}\")\n})?;","handlingStrategy":"try-catch","validationCode":"fn parse_unix_nanos_str(s: &str) -> Result<UnixNanos, String> {\n    let t = s.trim();\n    if t.is_empty() || !t.bytes().all(|b| b.is_ascii_digit()) {\n        return Err(format!(\"not a non-negative integer: '{s}'\"));\n    }\n    t.parse::<UnixNanos>().map_err(|e| e.to_string())\n}","typeGuard":"fn is_u64_literal(s: &str) -> bool {\n    !s.is_empty() && s.bytes().all(|b| b.is_ascii_digit())\n}","tryCatchPattern":"// Rust panics are not catchable in normal code; avoid the panic by\n// using the Result-returning path instead of From<&str>:\nlet ts: UnixNanos = s.trim().parse().map_err(|e| anyhow!(\"bad UnixNanos '{s}': {e}\"))?;","preventionTips":["Never use UnixNanos::from(&str) on untrusted strings; always prefer str::parse::<UnixNanos>().","Trim and digit-check strings from env/config/CSV before parsing.","Handle empty and missing fields explicitly rather than letting parse panic.","Reject float-formatted and unit-suffixed values at the schema level."],"tags":["rust","panic","parse-error","string-parsing","unix-nanos"],"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-14T00:17:10.932Z"}