toeverything/AFFiNE · error

Template doc(id: ${sourceDocId}) is removed, skip duplicate

Error message

Template doc(id: ${sourceDocId}) is removed, skip duplicate

What it means

Warning logged in `duplicateFromTemplate` when the source template doc is in the trash (removed). Duplication is skipped and the already-created target doc's id is still returned; the faulting input is a sourceDocId pointing at a trashed doc.

Source

Thrown at packages/frontend/core/src/modules/doc/services/docs.ts:314

      delete properties[key];
    });
    targetDoc.updateProperties(properties);

    return targetDocId;
  }

  /**
   * Duplicate a doc from template
   * @param sourceDocId - the id of the source doc to be duplicated
   * @param _targetDocId - the id of the target doc to be duplicated, if not provided, a new doc will be created
   * @returns the id of the new doc
   */
  async duplicateFromTemplate(sourceDocId: string, _targetDocId?: string) {
    const targetDocId = _targetDocId ?? this.createDoc().id;

    // check if source doc is removed
    if (this.list.doc$(sourceDocId).value?.trash$.value) {
      console.warn(
        `Template doc(id: ${sourceDocId}) is removed, skip duplicate`
      );
      return targetDocId;
    }

    const { release: sourceRelease, doc: sourceDoc } = this.open(sourceDocId);
    const { release: targetRelease, doc: targetDoc } = this.open(targetDocId);
    await sourceDoc.waitForSyncReady();

    // duplicate doc content
    try {
      const sourceBsDoc = this.store.getBlockSuiteDoc(sourceDocId);
      const targetBsDoc = this.store.getBlockSuiteDoc(targetDocId);
      if (!sourceBsDoc) throw new Error('Source doc not found');
      if (!targetBsDoc) throw new Error('Target doc not found');

      // clear the target doc (both surface and note)
      targetBsDoc.root?.children.forEach(child =>

View on GitHub (pinned to b4c8548c09)

Solutions

  1. No action needed; duplication of a removed template is skipped.
  2. Remove the stale template reference.
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when duplicateFromTemplate is called with a source doc that has been moved to trash, so duplication is skipped and the empty target doc id is returned.

Common situations: Occurs when duplicating from a template that was deleted. Restore the template doc from trash or choose another template.


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