{"record":{"id":"57b1b1d9411550d2","repo":"gitbutlerapp/gitbutler","slug":"system-clock-is-before-the-unix-epoch-err","errorCode":null,"errorMessage":"system clock is before the Unix epoch: {err}","messagePattern":"system clock is before the Unix epoch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/workspace.rs","lineNumber":333,"sourceCode":"            let code = failures\n                .iter()\n                .find_map(|(_, err)| err.custom_context().map(|ctx| ctx.code));\n            let joined = failures\n                .iter()\n                .map(|(remote, err)| format!(\"{remote}: {err}\"))\n                .collect::<Vec<_>>()\n                .join(\"\\n\");\n            let err = anyhow::anyhow!(joined);\n            match code {\n                Some(code) => err.context(code),\n                None => err,\n            }\n        })\n    })();\n\n    let attempted_ms = SystemTime::now()\n        .duration_since(UNIX_EPOCH)\n        .map_err(|err| anyhow::anyhow!(\"system clock is before the Unix epoch: {err}\"))?\n        .as_millis()\n        .try_into()\n        .map_err(|err| anyhow::anyhow!(\"fetch timestamp does not fit in the database: {err}\"))?;\n    let _guard = ctx.exclusive_worktree_access();\n    match &fetch_result {\n        Ok(ignored_errors) => ctx\n            .db\n            .get_cache_mut()?\n            .fetch_status_mut()\n            .record_success(attempted_ms, ignored_errors.as_deref())?,\n        Err(err) => ctx\n            .db\n            .get_cache_mut()?\n            .fetch_status_mut()\n            .record_failure(attempted_ms, &format!(\"{err:#}\"))?,\n    }\n\n    // A partial failure may still have updated some remote refs.","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/workspace.rs#L315-L351","documentation":"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.","triggerScenarios":"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.","commonSituations":"Freshly booted embedded devices or VMs without NTP; dual-boot systems with wrong hardware clock; containers with skewed clocks.","solutions":["Fix the system clock (enable NTP: `timedatectl set-ntp true`) or set the date manually","Resync the VM/host clock if running virtualized","Retry the fetch once the clock is correct"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// guard against a pre-epoch clock before fetching\nif std::time::SystemTime::now()\n    .duration_since(std::time::UNIX_EPOCH)\n    .is_err()\n{\n    return Err(anyhow!(\"system clock is before the Unix epoch; fix clock before fetching\"));\n}","typeGuard":null,"tryCatchPattern":"match workspace_fetch(ctx).await {\n    Err(e) if e.to_string().contains(\"system clock is before the Unix epoch\") => {\n        eprintln!(\"fix your system clock (enable NTP), then retry\");\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Enable NTP time synchronization on dev machines and VMs","Check clock sanity at app startup and warn early","Watch for clock skew in containers"],"tags":["time","clock","environment"],"backgroundTag":"invalid-env-var-value","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}