OpenBMB/ChatDev · error · FileExistsError
Destination already exists: {destination}
Error message
Destination already exists: {destination} What it means
Shared helper _clear_destination runs for rename_path, copy_path, and move_path when the destination already exists. Without overwrite=True the operation refuses to clobber the existing file or directory and raises FileExistsError naming the destination. This is a safety default against accidental data loss.
Source
Thrown at functions/function_calling/file.py:991
lines[start_idx:end_idx] = edit.replacement_lines
def _resolve_newline_choice(preference: str, detected: str) -> str:
normalized = (preference or "").lower()
if normalized == "lf":
return "\n"
if normalized == "crlf":
return "\r\n"
if normalized == "cr":
return "\r"
return detected or os.linesep
def _clear_destination(destination: Path, overwrite: bool) -> None:
if not destination.exists():
return
if not overwrite:
raise FileExistsError(f"Destination already exists: {destination}")
if destination.is_dir():
shutil.rmtree(destination)
else:
destination.unlink()
def _normalize_globs(patterns: Optional[Sequence[str]]) -> List[str]:
if not patterns:
return []
normalized: List[str] = []
for raw in patterns:
if not raw:
continue
normalized.append(str(raw))
return normalized
def _iter_candidate_files(View on GitHub (pinned to 4fb2db0ea9)
Solutions
- Pass overwrite=True if overwriting is intended and safe
- Delete or rename the conflicting destination first (or move to a unique name)
- Catch FileExistsError and treat as 'already done' for idempotent pipelines
Example fix
# before move_path(src="a.txt", dst="out/a.txt") # out/a.txt exists # after move_path(src="a.txt", dst="out/a.txt", overwrite=True)
Defensive patterns
Strategy: try-catch
Validate before calling
from pathlib import Path
if Path(dst).exists() and overwrite:
pass # proceed with overwrite=True
elif Path(dst).exists():
dst = unique_name(dst) # e.g. append -1, -2
move_path(src=src, dst=dst, overwrite=overwrite) Type guard
def destination_is_clear(dst) -> bool:
return not Path(dst).exists() Try / catch
try:
move_path(src=src, dst=dst)
except FileExistsError:
logging.info("destination exists; treating as already done: %s", dst)
# or: move_path(src=src, dst=dst, overwrite=True) if clobbering is safe Prevention
- Design move/copy scripts to be idempotent (skip on FileExistsError)
- Use unique destination names for archive-style operations
- Pass overwrite=True explicitly when clobbering is intended
When it happens
Trigger: Calling copy_path/move_path/rename_path where dst already exists and overwrite is False (the default); re-running a script after a partial failure left the destination in place; copying onto an existing directory.
Common situations: Idempotent re-runs of deployment/organization scripts; agents moving files into an archive that already contains a same-named entry; CI steps that rerun after retry.
Related errors
- Failed to copy workflow file
- Artifact file missing
- Session directory not found
- Failed to create zip archive
- Failed to save workflow file
AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27).
Data as JSON: /api/errors/3aeeef4dcf21c44b.
Report an issue: GitHub.