gitbutlerapp/gitbutler · error

system clock is before the Unix epoch

Error message

system clock is before the Unix epoch: {err}

What it means

Before recording fetch status, `workspace_fetch_from_remotes` reads `SystemTime::now()` and converts the duration since the Unix epoch to milliseconds. If the system clock is set before 1970, `duration_since(UNIX_EPOCH)` fails and this error is raised.

Solutions

  1. Fix the system clock (enable NTP: `timedatectl set-ntp true`) or set the date manually
  2. Resync the VM/host clock if running virtualized
  3. Retry the fetch once the clock is correct
Defensive patterns

Strategy: validation

Validate before calling

// guard against a pre-epoch clock before fetching
if std::time::SystemTime::now()
    .duration_since(std::time::UNIX_EPOCH)
    .is_err()
{
    return Err(anyhow!("system clock is before the Unix epoch; fix clock before fetching"));
}

Try / catch

match workspace_fetch(ctx).await {
    Err(e) if e.to_string().contains("system clock is before the Unix epoch") => {
        eprintln!("fix your system clock (enable NTP), then retry");
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling `workspace_fetch` on a machine whose system clock is set to a pre-epoch time (before 1970) — e.g. dead RTC battery, VM clock not synced, or manual misconfiguration.

Common situations: Freshly booted embedded devices or VMs without NTP; dual-boot systems with wrong hardware clock; containers with skewed clocks.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/57b1b1d9411550d2. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-api/src/workspace.rs:333

            let code = failures
                .iter()
                .find_map(|(_, err)| err.custom_context().map(|ctx| ctx.code));
            let joined = failures
                .iter()
                .map(|(remote, err)| format!("{remote}: {err}"))
                .collect::<Vec<_>>()
                .join("\n");
            let err = anyhow::anyhow!(joined);
            match code {
                Some(code) => err.context(code),
                None => err,
            }
        })
    })();

    let attempted_ms = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .map_err(|err| anyhow::anyhow!("system clock is before the Unix epoch: {err}"))?
        .as_millis()
        .try_into()
        .map_err(|err| anyhow::anyhow!("fetch timestamp does not fit in the database: {err}"))?;
    let _guard = ctx.exclusive_worktree_access();
    match &fetch_result {
        Ok(ignored_errors) => ctx
            .db
            .get_cache_mut()?
            .fetch_status_mut()
            .record_success(attempted_ms, ignored_errors.as_deref())?,
        Err(err) => ctx
            .db
            .get_cache_mut()?
            .fetch_status_mut()
            .record_failure(attempted_ms, &format!("{err:#}"))?,
    }

    // A partial failure may still have updated some remote refs.

View on GitHub (pinned to 58e5313667)