toeverything/AFFiNE · error · Error
Can not find the current version of the doc.
Error message
Can not find the current version of the doc.
What it means
Thrown during rollbackDoc when getDocSnapshot(spaceId, docId) returns no current snapshot. Even though the target history snapshot exists, the doc has no live 'current' bin to diff against, so generateChangeUpdate has nothing to compute from. This usually indicates the doc was deleted or never had its snapshot materialized.
Source
Thrown at packages/backend/server/src/core/doc/storage/doc.ts:254
abstract deleteDoc(spaceId: string, docId: string): Promise<void>;
abstract deleteSpace(spaceId: string): Promise<void>;
async rollbackDoc(
spaceId: string,
docId: string,
timestamp: number,
editorId?: string
): Promise<void> {
await using _lock = await this.lockDocForUpdate(spaceId, docId);
const toSnapshot = await this.getDocHistory(spaceId, docId, timestamp);
if (!toSnapshot) {
throw new Error('Can not find the version to rollback to.');
}
const fromSnapshot = await this.getDocSnapshot(spaceId, docId);
if (!fromSnapshot) {
throw new Error('Can not find the current version of the doc.');
}
const change = this.generateChangeUpdate(fromSnapshot.bin, toSnapshot.bin);
await this.pushDocUpdates(spaceId, docId, [change], editorId);
// force create a new history record after rollback
await this.createDocHistory(fromSnapshot, true);
}
abstract getSpaceDocTimestamps(
spaceId: string,
after?: number
): Promise<Record<string, number> | null>;
abstract listDocHistories(
spaceId: string,
docId: string,
query: { skip?: number; limit?: number }
): Promise<{ timestamp: number; editor: Editor | null }[]>;
abstract getDocHistory(View on GitHub (pinned to 26c515e050)
Solutions
- Check whether the doc still exists via getDocSnapshot before offering rollback in the UI; hide the action if no current snapshot.
- Reconcile the snapshot table with the history table for the affected docId (re-materialize the snapshot from the latest history).
- If the doc was intentionally deleted, prevent rollback by filtering deleted docs out of the history browser.
- Map to a typed NotFound/Conflict error and return 404/409 instead of a generic 500.
Example fix
// before
const fromSnapshot = await this.getDocSnapshot(spaceId, docId);
if (!fromSnapshot) {
throw new Error('Can not find the current version of the doc.');
}
// after
const fromSnapshot = await this.getDocSnapshot(spaceId, docId);
if (!fromSnapshot) {
throw new ConflictException(
`Doc ${docId} has no current snapshot; cannot compute rollback delta`
);
} Defensive patterns
Strategy: validation
Validate before calling
async function assertCurrentSnapshot(storage, ws, doc) {
const snap = await storage.getDocSnapshot(ws, doc);
if (!snap?.bin) {
throw new UserError(`Doc ${doc} has no current snapshot; rollback unavailable`);
}
return snap;
} Type guard
function isCurrentSnapshotMissing(e: unknown): boolean {
return e instanceof Error && e.message === 'Can not find the current version of the doc.';
} Try / catch
try {
await doc.rollbackDoc(ws, doc, ts);
} catch (e) {
if (isCurrentSnapshotMissing(e)) {
return res.status(409).send('Doc snapshot missing; cannot roll back');
}
throw e;
} Prevention
- Reconcile snapshot vs history tables during migrations.
- Disable rollback UI for docs whose snapshot is missing.
- Audit deleteDoc paths to ensure snapshots aren't orphaned from history.
When it happens
Trigger: Rolling back a doc that has history rows but whose current snapshot row is missing (deleted doc, partially-migrated doc, snapshot table out of sync with history table). Also possible right after a deleteDoc that removed the snapshot but left orphaned history.
Common situations: Post-migration data inconsistency between snapshot and history tables. A doc that was soft/hard deleted while a rollback request was in flight. Storage backend (S3/DB) partial failure that wrote history but not the snapshot.
Related errors
- doc_not_found
- Can not find the version to rollback to.
- doc_history_not_found
- Workspace ${workspaceId} not found or has no root document
- Document ${docId} not found
AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12).
Data as JSON: /api/errors/c7f0889160c615ba.
Report an issue: GitHub.