{"record":{"id":"e0b8a9da70f56c87","repo":"sxyazi/yazi","slug":"time-went-backwards","errorCode":null,"errorMessage":"Time went backwards","messagePattern":"Time went backwards","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"yazi-shared/src/time.rs","lineNumber":5,"sourceCode":"use std::time::{SystemTime, UNIX_EPOCH};\n\n#[inline]\npub fn timestamp_us() -> u64 {\n\tSystemTime::now().duration_since(UNIX_EPOCH).expect(\"Time went backwards\").as_micros() as _\n}\n","sourceCodeStart":1,"sourceCodeEnd":7,"githubUrl":"https://github.com/sxyazi/yazi/blob/94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2/yazi-shared/src/time.rs#L1-L7","documentation":"yazi_shared::time::timestamp_us() computes SystemTime::now().duration_since(UNIX_EPOCH); if the wall clock reads earlier than 1970-01-01 UTC, duration_since returns Err and the expect panics with this message. The helper supplies microsecond timestamps throughout yazi, so the panic can fire from almost any subsystem.","triggerScenarios":"Any call to timestamp_us() while the system clock is pre-epoch: a dead CMOS battery resetting the RTC, a VM restored from snapshot with a corrupted clock, the clock deliberately set back before 1970, or a test rig mocking time below the epoch.","commonSituations":"Bare-metal or embedded boards after power loss without NTP; VM/containers inheriting a wrong host clock; test environments with incorrectly faked clocks.","solutions":["Correct the system clock and enable NTP — this is the only real cause","Enable host time synchronization for VMs (VMware Tools, Hyper-V time sync) after snapshot restores","In tests, never fake time below the epoch; mock at a layer that returns a sane u64 instead","In your own code paths, use a checked conversion (duration_since(...).unwrap_or_default()) instead of the panicking helper"],"exampleFix":"// before\nlet ts = yazi_shared::time::timestamp_us(); // panics when clock < 1970-01-01\n\n// after (your own wrapper)\nlet ts = SystemTime::now()\n    .duration_since(UNIX_EPOCH)\n    .map(|d| d.as_micros() as u64)\n    .unwrap_or(0); // degrade gracefully instead of panicking","handlingStrategy":"validation","validationCode":"use std::time::{SystemTime, UNIX_EPOCH};\n\nfn clock_sane() -> bool { SystemTime::now() > UNIX_EPOCH }\n\n// gate clock-dependent work:\nassert!(clock_sane(), \"system clock is before 1970-01-01; fix the RTC / enable NTP\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable NTP/chrony so the clock never sits before the epoch","After VM snapshot restores, force a host time sync before starting yazi","In tests, mock time at a layer that returns a sane u64; never below the epoch"],"tags":["time","clock","panic","environment"],"backgroundTag":null,"analyzedSha":"94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2","analyzedAt":"2026-08-16T09:56:24.836Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}