sxyazi/yazi · critical

Time went backwards

Error message

Time went backwards

What it means

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.

Source

Thrown at yazi-shared/src/time.rs:5

use std::time::{SystemTime, UNIX_EPOCH};

#[inline]
pub fn timestamp_us() -> u64 {
	SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards").as_micros() as _
}

View on GitHub (pinned to 94abcfa92f)

Solutions

  1. Correct the system clock and enable NTP — this is the only real cause
  2. Enable host time synchronization for VMs (VMware Tools, Hyper-V time sync) after snapshot restores
  3. In tests, never fake time below the epoch; mock at a layer that returns a sane u64 instead
  4. In your own code paths, use a checked conversion (duration_since(...).unwrap_or_default()) instead of the panicking helper

Example fix

// before
let ts = yazi_shared::time::timestamp_us(); // panics when clock < 1970-01-01

// after (your own wrapper)
let ts = SystemTime::now()
    .duration_since(UNIX_EPOCH)
    .map(|d| d.as_micros() as u64)
    .unwrap_or(0); // degrade gracefully instead of panicking
Defensive patterns

Strategy: validation

Validate before calling

use std::time::{SystemTime, UNIX_EPOCH};

fn clock_sane() -> bool { SystemTime::now() > UNIX_EPOCH }

// gate clock-dependent work:
assert!(clock_sane(), "system clock is before 1970-01-01; fix the RTC / enable NTP");

Prevention

When it happens

Trigger: 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.

Common situations: Bare-metal or embedded boards after power loss without NTP; VM/containers inheriting a wrong host clock; test environments with incorrectly faked clocks.

Related errors


AI-assisted analysis of sxyazi/yazi@94abcfa92f (2026-08-16). Data as JSON: /api/errors/e0b8a9da70f56c87. Report an issue: GitHub.