{"record":{"id":"fe84dcc07e46989c","repo":"toeverything/AFFiNE","slug":"cannot-move-a-node-to-itself","errorCode":null,"errorMessage":"Cannot move a node to itself","messagePattern":"Cannot move a node to itself","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/frontend/core/src/modules/organize/stores/folder.ts","lineNumber":134,"sourceCode":"  }\n\n  removeLink(linkId: string) {\n    const link = this.dbService.db.folders.get(linkId);\n    if (link === null || link.type === 'folder') {\n      throw new Error('Link not found');\n    }\n    this.dbService.db.folders.delete(linkId);\n  }\n\n  moveNode(nodeId: string, parentId: string | null, index: string) {\n    const node = this.dbService.db.folders.get(nodeId);\n    if (node === null) {\n      throw new Error('Node not found');\n    }\n\n    if (parentId) {\n      if (nodeId === parentId) {\n        throw new Error('Cannot move a node to itself');\n      }\n      if (this.isAncestor(parentId, nodeId)) {\n        throw new Error('Cannot move a node to its descendant');\n      }\n      const parent = this.dbService.db.folders.get(parentId);\n      if (parent === null || parent.type !== 'folder') {\n        throw new Error('Parent folder not found');\n      }\n    } else {\n      if (node.type !== 'folder') {\n        throw new Error('Root node can only have folders');\n      }\n    }\n    this.dbService.db.folders.update(nodeId, {\n      parentId,\n      index,\n    });\n  }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/frontend/core/src/modules/organize/stores/folder.ts#L116-L152","documentation":"A cycle guard in moveNode: when moving nodeId under a non-null parentId, the first check rejects the degenerate case where the node would become its own parent (nodeId === parentId). It fires when a move request designates the node itself as the new parent folder.","triggerScenarios":"Thrown by moveNode when nodeId equals parentId, i.e. a drag-and-drop or move operation targets the node itself as its new parent.","commonSituations":"Happens when a user drags a folder onto itself in the organize tree. Drop the node onto a different destination folder.","solutions":["Choose a different destination folder.","Guard the move operation against identical source and target."],"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"}