{"record":{"id":"2ce5c5ba9fdf1340","repo":"affaan-m/ECC","slug":"fileexistserror-destination","errorCode":null,"errorMessage":"FileExistsError(destination)","messagePattern":"FileExistsError\\(destination\\)","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"skills/taste-application/scripts/tasteforge/media/common.py","lineNumber":22,"sourceCode":"import os\nimport tempfile\nfrom contextlib import contextmanager\nfrom pathlib import Path\n\n\ndef geometry(width, height, fps, duration=1):\n    for value in (width, height, fps, duration):\n        if isinstance(value, bool) or not math.isfinite(value) or value <= 0:\n            raise ValueError(\"Geometry, fps and duration must be finite and positive\")\n    if width != int(width) or height != int(height) or width % 2 or height % 2:\n        raise ValueError(\"Width and height must be even integers\")\n\n\n@contextmanager\ndef output_file(destination, overwrite=False):\n    destination = Path(destination)\n    if os.path.lexists(destination) and not overwrite:\n        raise FileExistsError(destination)\n    destination.parent.mkdir(parents=True, exist_ok=True)\n    fd, filename = tempfile.mkstemp(\n        prefix=\".media-\", suffix=destination.suffix, dir=destination.parent\n    )\n    os.close(fd)\n    temporary = Path(filename)\n    try:\n        yield temporary\n        if temporary.stat().st_size == 0:\n            raise RuntimeError(\"Media command produced an empty output\")\n        if overwrite:\n            os.replace(temporary, destination)\n        else:\n            os.link(temporary, destination)\n    finally:\n        temporary.unlink(missing_ok=True)\n","sourceCodeStart":4,"sourceCodeEnd":39,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/taste-application/scripts/tasteforge/media/common.py#L4-L39","documentation":"output_file is a context manager that safely writes media to a destination path via a temporary file. It raises FileExistsError when the destination path already exists (or is a dangling symlink) and the caller did not pass overwrite=True. This prevents accidentally destroying existing media files.","triggerScenarios":"Calling render() or make_clip() with an output path that already exists on disk without overwrite=True; the destination being a broken symlink caught by os.path.lexists.","commonSituations":"Re-running a render pipeline that wrote to the same output filename previously; forgetting to pass overwrite=True when intentionally replacing an old clip; stale output left over from a previous failed run.","solutions":["Delete or move the existing file at the destination path before re-running","Pass overwrite=True to the render/make_clip call (it forwards to output_file) to replace the existing file atomically via os.replace","Choose a different output filename"],"exampleFix":"// before\nrender(src, start, output='out.mp4')  # out.mp4 exists -> FileExistsError\n// after\nrender(src, start, output='out.mp4', overwrite=True)","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\nimport os\nif os.path.lexists(out_path) and not overwrite:\n    raise FileExistsError(out_path)  # or handle before calling","typeGuard":null,"tryCatchPattern":"try:\n    render(src, start, output=out_path)\nexcept FileExistsError:\n    render(src, start, output=out_path, overwrite=True)  # or pick a new name","preventionTips":["Check os.path.lexists(destination) before rendering","Always pass overwrite=True when regeneration is intended","Use unique, timestamped output filenames in pipelines","Clean stale outputs from failed runs before retrying"],"tags":["filesystem","media","overwrite"],"backgroundTag":"file-already-exists","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}