Tencent/WeKnora · error

cannot move a folder into its own descendant

Error message

cannot move a folder into its own descendant

What it means

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.

Source

Thrown at internal/application/service/wiki_page.go:1652

	}

	targetParent := folder.ParentID
	if moveParent {
		targetParent = newParentID
	}

	parentPath := ""
	depthBase := 0
	if targetParent != types.WikiFolderRootID {
		if targetParent == folder.ID {
			return nil, errors.New("cannot move a folder into itself")
		}
		parent, err := s.repo.GetFolderByID(ctx, kbID, targetParent)
		if err != nil {
			return nil, err
		}
		if parent.Path == folder.Path || strings.HasPrefix(parent.Path, folder.Path+"/") {
			return nil, errors.New("cannot move a folder into its own descendant")
		}
		parentPath = parent.Path
		depthBase = parent.Depth
	}

	if existing, err := s.repo.GetChildFolderByName(ctx, kbID, targetParent, name); err == nil {
		if existing.ID != folder.ID {
			return nil, repository.ErrWikiFolderConflict
		}
	} else if !errors.Is(err, repository.ErrWikiFolderNotFound) {
		return nil, err
	}

	oldPath := folder.Path
	newPath := name
	if parentPath != "" {
		newPath = parentPath + "/" + name
	}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Pick a target parent outside the folder's own subtree
  2. Fix the client so it excludes the folder's descendants from valid drop targets
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/application/service/wiki_page.go:1652 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/fcaed9f05c72fb62. Report an issue: GitHub.