HKUDS/DeepTutor · error · HTTPException

' ' already exists in the target folder

Error message

'{src.name}' already exists in the target folder

What it means

Collision guard in POST /{kb_name}/files/move: an entry with the same name as the source already exists at the computed destination (dest_dir / src.name). The move is refused rather than silently overwriting the existing file or folder.

Solutions

  1. Rename the source before moving
  2. Remove or rename the existing entry in the target folder first
  3. Pick a different destination folder
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at deeptutor/api/routers/knowledge.py:2433 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/4499fd00094b0e25. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/api/routers/knowledge.py:2433

    raw_dir = manager.get_knowledge_base_path(kb_name) / "raw"

    source_rel = _sanitize_rel_subdir(payload.source)
    if not source_rel:
        raise HTTPException(status_code=400, detail="Source path is required")
    src = _safe_join_raw(raw_dir, source_rel)
    if not src.exists():
        raise HTTPException(status_code=404, detail="Source not found")

    dest_folder = _sanitize_rel_subdir(payload.dest_folder)
    dest_dir = _safe_join_raw(raw_dir, dest_folder) if dest_folder else raw_dir.resolve()
    dest = dest_dir / src.name

    if dest.resolve() == src.resolve():
        return {"status": "ok", "path": source_rel}
    if src.is_dir() and dest_dir.resolve().is_relative_to(src.resolve()):
        raise HTTPException(status_code=400, detail="Cannot move a folder into itself")
    if dest.exists():
        raise HTTPException(
            status_code=409,
            detail=f"'{src.name}' already exists in the target folder",
        )

    dest_dir.mkdir(parents=True, exist_ok=True)
    shutil.move(str(src), str(dest))
    return {"status": "ok", "path": dest.relative_to(raw_dir.resolve()).as_posix()}


@router.get("/{kb_name}/file-preview-text/{filename:path}")
async def serve_kb_raw_file_text_preview(kb_name: str, filename: str):
    """Serve extracted plain text for a raw KB document preview."""
    target = _resolve_kb_raw_file_or_404(kb_name, filename)
    try:
        text = extract_text_from_path(
            target,
            max_bytes=DocumentValidator.MAX_FILE_SIZE,
            max_chars=MAX_EXTRACTED_CHARS_PER_DOC,

View on GitHub (pinned to 3e82f13042)