toeverything/AFFiNE · error
Failed to extract markdown, snapshot is undefined
Error message
Failed to extract markdown, snapshot is undefined
What it means
Thrown in extractMarkdownFromDoc when the transformer produces an undefined snapshot while converting the doc's note models to markdown via the MarkdownAdapter, meaning the doc could not be serialized for AI extraction.
Source
Thrown at packages/frontend/core/src/blocksuite/ai/utils/extract.ts:216
}
export async function extractMarkdownFromDoc(doc: Store): Promise<string> {
const std = new BlockStdScope({
store: doc,
extensions: getStoreManager().config.init().value.get('store'),
});
const transformer = await getTransformer(doc);
const adapter = new MarkdownAdapter(transformer, std.provider);
const blockModels = getNoteBlockModels(doc);
const textModels = blockModels.filter(
model => !matchModels(model, [ImageBlockModel, DatabaseBlockModel])
);
const drafts = textModels.map(toDraftModel);
const slice = Slice.fromModels(doc, drafts);
const snapshot = transformer.sliceToSnapshot(slice);
if (!snapshot) {
throw new Error('Failed to extract markdown, snapshot is undefined');
}
const content = await adapter.fromSliceSnapshot({
snapshot,
assets: transformer.assetsManager,
});
return content.file;
}
function getNoteBlockModels(doc: Store) {
const notes = doc
.getBlocksByFlavour('affine:note')
.filter(
note =>
(note.model as NoteBlockModel).props.displayMode !==
NoteDisplayMode.EdgelessOnly
)
.map(note => note.model as NoteBlockModel);
const blockModels = notes.reduce((acc, note) => {View on GitHub (pinned to b4c8548c09)
Solutions
- Obtain a valid snapshot first; do not call markdown extraction with an undefined snapshot.
- Check snapshot retrieval errors upstream before extracting.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown in extractMarkdownFromDoc when transformer.sliceToSnapshot returns undefined for the slice built from the doc's note block models, aborting markdown extraction.
Common situations: Happens when converting a page to markdown for AI features and the slice snapshot fails. Reopen the page or retry once the doc has fully loaded.
AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18).
Data as JSON: /api/errors/0bb9d54e9cc52657.
Report an issue: GitHub.