{"record":{"id":"65f917da3c66ede2","repo":"Tencent/WeKnora","slug":"cannot-move-a-folder-into-itself","errorCode":null,"errorMessage":"cannot move a folder into itself","messagePattern":"cannot move a folder into itself","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/wiki_page.go","lineNumber":1645,"sourceCode":"\t}\n\n\tname := folder.Name\n\tif strings.TrimSpace(newName) != \"\" {\n\t\tif name, err = validateFolderName(newName); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\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","sourceCodeStart":1627,"sourceCodeEnd":1663,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/wiki_page.go#L1627-L1663","documentation":"Raised in RenameOrMoveFolder when moving a folder whose target parent (newParentID) equals the folder's own ID — a folder cannot become its own child, which would create a cycle in the wiki folder tree. Structural-invariant guard.","triggerScenarios":"Thrown at internal/application/service/wiki_page.go:1645 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a different target parent folder","Skip the move when the client sends the folder's own id as parent"],"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"}