{"record":{"id":"fcaed9f05c72fb62","repo":"Tencent/WeKnora","slug":"cannot-move-a-folder-into-its-own-descendant","errorCode":null,"errorMessage":"cannot move a folder into its own descendant","messagePattern":"cannot move a folder into its own descendant","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/wiki_page.go","lineNumber":1652,"sourceCode":"\t}\n\n\ttargetParent := folder.ParentID\n\tif moveParent {\n\t\ttargetParent = newParentID\n\t}\n\n\tparentPath := \"\"\n\tdepthBase := 0\n\tif targetParent != types.WikiFolderRootID {\n\t\tif targetParent == folder.ID {\n\t\t\treturn nil, errors.New(\"cannot move a folder into itself\")\n\t\t}\n\t\tparent, err := s.repo.GetFolderByID(ctx, kbID, targetParent)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif parent.Path == folder.Path || strings.HasPrefix(parent.Path, folder.Path+\"/\") {\n\t\t\treturn nil, errors.New(\"cannot move a folder into its own descendant\")\n\t\t}\n\t\tparentPath = parent.Path\n\t\tdepthBase = parent.Depth\n\t}\n\n\tif existing, err := s.repo.GetChildFolderByName(ctx, kbID, targetParent, name); err == nil {\n\t\tif existing.ID != folder.ID {\n\t\t\treturn nil, repository.ErrWikiFolderConflict\n\t\t}\n\t} else if !errors.Is(err, repository.ErrWikiFolderNotFound) {\n\t\treturn nil, err\n\t}\n\n\toldPath := folder.Path\n\tnewPath := name\n\tif parentPath != \"\" {\n\t\tnewPath = parentPath + \"/\" + name\n\t}","sourceCodeStart":1634,"sourceCodeEnd":1670,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L1634-L1670","documentation":"Raised in RenameOrMoveFolder when the target parent's path equals the folder's path or lies beneath it (parent.Path prefix of folder.Path) — moving a folder into one of its own descendants would corrupt the tree. Cycle guard after loading the parent row.","triggerScenarios":"Thrown at internal/application/service/wiki_page.go:1652 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pick a target parent outside the folder's own subtree","Fix the client so it excludes the folder's descendants from valid drop targets"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}