{"record":{"id":"ba1f528d4c1f58da","repo":"nautechsystems/nautilus_trader","slug":"seconds-timestamp-should-be-within-valid-range-ba1f52","errorCode":null,"errorMessage":"seconds timestamp should be within valid range","messagePattern":"seconds timestamp should be within valid range","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/generators/position_id.rs","lineNumber":135,"sourceCode":"    #[inline]\n    fn refresh_fixed_prefix(&mut self, timestamp_ms: u64) {\n        let epoch_second = timestamp_ms / 1_000;\n        if epoch_second == self.epoch_second {\n            return;\n        }\n\n        write_fixed_prefix(&mut self.buf, &self.trader_tag, epoch_second);\n        self.fixed_prefix_len = self.buf.len();\n        self.epoch_second = epoch_second;\n    }\n}\n\nfn write_fixed_prefix(buf: &mut String, trader_tag: &str, epoch_second: u64) {\n    let now_utc = Offset::UTC.to_datetime(\n        Timestamp::from_second(\n            i64::try_from(epoch_second).expect(\"seconds timestamp should fit i64\"),\n        )\n        .expect(\"seconds timestamp should be within valid range\"),\n    );\n\n    buf.clear();\n\n    write!(\n        buf,\n        \"P-{:04}{:02}{:02}-{:02}{:02}{:02}-{trader_tag}-\",\n        now_utc.year(),\n        now_utc.month(),\n        now_utc.day(),\n        now_utc.hour(),\n        now_utc.minute(),\n        now_utc.second(),\n    )\n    .expect(\"writing to String should not fail\");\n}\n\n#[cfg(test)]","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/generators/position_id.rs#L117-L153","documentation":"This panic comes from `Timestamp::from_second(...).expect(\"seconds timestamp should be within valid range\")` in `write_fixed_prefix` in crates/common/src/generators/position_id.rs. The epoch seconds fit into i64 but fall outside the range jiff accepts for a Timestamp (approximately years -9999..9999), so construction fails and the expect panics.","triggerScenarios":"Calling `refresh_fixed_prefix` for the PositionIdGenerator with epoch seconds outside jiff's valid range: above 253402300799 (year 9999) or below -377705023201.","commonSituations":"Mock clock fixtures using i64::MIN/MAX, timestamps corrupted by bad unit conversion (e.g. nanoseconds passed as seconds), or deserialized garbage values routed into the generator.","solutions":["Ensure the value is seconds (not nanos/millis); a nanosecond timestamp passed as seconds overflows the valid range","Range-check before calling: `-377705023201 <= secs <= 253402300799`","Correct the clock/mock source to produce realistic epoch seconds"],"exampleFix":"// before\nlet secs = nanos / 1; // wrong units: nanos treated as seconds\nlet _ = generator.refresh_fixed_prefix(u64::try_from(secs).unwrap());\n// after\nlet secs = nanos / 1_000_000_000; // convert nanos to seconds\nassert!((-377705023201i64..=253402300799).contains(&secs));\nlet _ = generator.refresh_fixed_prefix(u64::try_from(secs).unwrap());","handlingStrategy":"validation","validationCode":"fn in_jiff_range(secs: i64) -> bool { (-377705023201..=253402300799).contains(&secs) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify unit conversions (nanos/millis -> seconds) before generating IDs","Keep test timestamps within jiff's supported range"],"tags":["rust","panic","timestamp","jiff"],"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-14T05:17:10.506Z"}