toeverything/AFFiNE · error · Error

PdfAdapter does not support importing slices from PDF.

Error message

PdfAdapter does not support importing slices from PDF.

What it means

toSliceSnapshot on PdfAdapter is an intentionally unimplemented adapter method: PDF exports cannot be turned into slice snapshots, so any attempt to import a slice from a PDF hits this hard rejection. It fires when a caller passes a ToSliceSnapshotPayload<PdfAdapterFile> to this adapter.

Source

Thrown at blocksuite/affine/shared/src/adapters/pdf/pdf.ts:156

      },
      assetsIds: [],
    };
  }

  toBlockSnapshot(
    _payload: ToBlockSnapshotPayload<PdfAdapterFile>
  ): BlockSnapshot {
    throw new Error('PdfAdapter does not support importing blocks from PDF.');
  }

  toDocSnapshot(_payload: ToDocSnapshotPayload<PdfAdapterFile>): DocSnapshot {
    throw new Error('PdfAdapter does not support importing docs from PDF.');
  }

  toSliceSnapshot(
    _payload: ToSliceSnapshotPayload<PdfAdapterFile>
  ): SliceSnapshot | null {
    throw new Error('PdfAdapter does not support importing slices from PDF.');
  }

  /**
   * Get the pdfmake document definition (for testing purposes)
   */
  async getDocDefinition(
    blocks: BlockSnapshot[],
    title?: string,
    assets?: FromDocSnapshotPayload['assets']
  ): Promise<TDocumentDefinitions> {
    const content = await this._buildContent(blocks, assets);
    return this._createDocDefinition(title, content);
  }

  private async _buildContent(
    blocks: BlockSnapshot[],
    assets?: FromDocSnapshotPayload['assets']
  ): Promise<Content[]> {

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Slice-level PDF import is not supported. Import the content at block or doc level using another adapter, or extract the PDF content externally first.
  2. Add a capability check before calling toSliceSnapshot on PdfAdapter and gracefully degrade to a 'not supported' notification.

Example fix

try {
  await pdfAdapter.toSliceSnapshot(payload);
} catch {
  // PDF slice import unsupported — extract content with pdf.js instead
  const text = await extractPdfText(file);
  return markdownAdapter.toSliceSnapshot({ file: text, assets, workspaceId, pageId });
}
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at blocksuite/affine/shared/src/adapters/pdf/pdf.ts:156 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/f7d492cd63e98512. Report an issue: GitHub.