{"record":{"id":"16d8bfcfb86b3453","repo":"toeverything/AFFiNE","slug":"template-doc-id-sourcedocid-is-removed-skip","errorCode":null,"errorMessage":"Template doc(id: ${sourceDocId}) is removed, skip duplicate","messagePattern":"Template doc\\(id: (.+?)\\) is removed, skip duplicate","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/frontend/core/src/modules/doc/services/docs.ts","lineNumber":314,"sourceCode":"      delete properties[key];\n    });\n    targetDoc.updateProperties(properties);\n\n    return targetDocId;\n  }\n\n  /**\n   * Duplicate a doc from template\n   * @param sourceDocId - the id of the source doc to be duplicated\n   * @param _targetDocId - the id of the target doc to be duplicated, if not provided, a new doc will be created\n   * @returns the id of the new doc\n   */\n  async duplicateFromTemplate(sourceDocId: string, _targetDocId?: string) {\n    const targetDocId = _targetDocId ?? this.createDoc().id;\n\n    // check if source doc is removed\n    if (this.list.doc$(sourceDocId).value?.trash$.value) {\n      console.warn(\n        `Template doc(id: ${sourceDocId}) is removed, skip duplicate`\n      );\n      return targetDocId;\n    }\n\n    const { release: sourceRelease, doc: sourceDoc } = this.open(sourceDocId);\n    const { release: targetRelease, doc: targetDoc } = this.open(targetDocId);\n    await sourceDoc.waitForSyncReady();\n\n    // duplicate doc content\n    try {\n      const sourceBsDoc = this.store.getBlockSuiteDoc(sourceDocId);\n      const targetBsDoc = this.store.getBlockSuiteDoc(targetDocId);\n      if (!sourceBsDoc) throw new Error('Source doc not found');\n      if (!targetBsDoc) throw new Error('Target doc not found');\n\n      // clear the target doc (both surface and note)\n      targetBsDoc.root?.children.forEach(child =>","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/frontend/core/src/modules/doc/services/docs.ts#L296-L332","documentation":"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.","triggerScenarios":"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.","commonSituations":"Occurs when duplicating from a template that was deleted. Restore the template doc from trash or choose another template.","solutions":["No action needed; duplication of a removed template is skipped.","Remove the stale template reference."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}