gitbutlerapp/gitbutler · error

fetch timestamp does not fit in the database

Error message

fetch timestamp does not fit in the database: {err}

What it means

After computing the epoch-millisecond fetch timestamp, the value is cast with `try_into()` into the integer type stored in the database (e.g. i64). If the millisecond value does not fit that type, this error is raised.

Solutions

  1. Fix the system clock to the current date/time
  2. Verify the database schema's timestamp column type is large enough (i64 millis)
  3. Retry the fetch after correcting the clock
Defensive patterns

Strategy: validation

Validate before calling

// ensure the current timestamp fits the storage integer type
let ms: i64 = std::time::SystemTime::now()
    .duration_since(std::time::UNIX_EPOCH)?
    .as_millis()
    .try_into()
    .map_err(|_| anyhow!("clock far in the future; timestamp overflow"))?;

Try / catch

match workspace_fetch(ctx).await {
    Err(e) if e.to_string().contains("fetch timestamp does not fit") => {
        eprintln!("system clock is wildly wrong; correct date and retry");
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling `workspace_fetch` when `SystemTime::now()` since epoch in milliseconds exceeds the target database column/field integer range — practically only with far-future system clocks (year ~292 million+ for i64, or smaller storage types sooner).

Common situations: System clock wildly wrong (set to year 3000+ by misconfiguration or a prank/test); database schema stores timestamps in a narrower integer type.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

            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.
    ctx.invalidate_workspace_cache()?;
    prune_missing_branch_stack_order(ctx)?;
    fetch_result.map(|_| ())

View on GitHub (pinned to 58e5313667)