{"record":{"id":"3aeeef4dcf21c44b","repo":"OpenBMB/ChatDev","slug":"destination-already-exists-destination","errorCode":null,"errorMessage":"Destination already exists: {destination}","messagePattern":"Destination already exists: (.+?)","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"functions/function_calling/file.py","lineNumber":991,"sourceCode":"        lines[start_idx:end_idx] = edit.replacement_lines\n\n\ndef _resolve_newline_choice(preference: str, detected: str) -> str:\n    normalized = (preference or \"\").lower()\n    if normalized == \"lf\":\n        return \"\\n\"\n    if normalized == \"crlf\":\n        return \"\\r\\n\"\n    if normalized == \"cr\":\n        return \"\\r\"\n    return detected or os.linesep\n\n\ndef _clear_destination(destination: Path, overwrite: bool) -> None:\n    if not destination.exists():\n        return\n    if not overwrite:\n        raise FileExistsError(f\"Destination already exists: {destination}\")\n    if destination.is_dir():\n        shutil.rmtree(destination)\n    else:\n        destination.unlink()\n\n\ndef _normalize_globs(patterns: Optional[Sequence[str]]) -> List[str]:\n    if not patterns:\n        return []\n    normalized: List[str] = []\n    for raw in patterns:\n        if not raw:\n            continue\n        normalized.append(str(raw))\n    return normalized\n\n\ndef _iter_candidate_files(","sourceCodeStart":973,"sourceCodeEnd":1009,"githubUrl":"https://github.com/OpenBMB/ChatDev/blob/4fb2db0ea90375ce1059f44fe03ffbd191a7a169/functions/function_calling/file.py#L973-L1009","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nmove_path(src=\"a.txt\", dst=\"out/a.txt\")  # out/a.txt exists\n# after\nmove_path(src=\"a.txt\", dst=\"out/a.txt\", overwrite=True)","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nif Path(dst).exists() and overwrite:\n    pass  # proceed with overwrite=True\nelif Path(dst).exists():\n    dst = unique_name(dst)  # e.g. append -1, -2\nmove_path(src=src, dst=dst, overwrite=overwrite)","typeGuard":"def destination_is_clear(dst) -> bool:\n    return not Path(dst).exists()","tryCatchPattern":"try:\n    move_path(src=src, dst=dst)\nexcept FileExistsError:\n    logging.info(\"destination exists; treating as already done: %s\", dst)\n    # or: move_path(src=src, dst=dst, overwrite=True) if clobbering is safe","preventionTips":["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"],"tags":["filesystem","copy","move","file-exists"],"backgroundTag":"file-already-exists","analyzedSha":"4fb2db0ea90375ce1059f44fe03ffbd191a7a169","analyzedAt":"2026-08-27T14:35:29.622Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}