{"record":{"id":"3c878b4e676947aa","repo":"calesthio/OpenMontage","slug":"cannot-upload-file-not-found-path","errorCode":null,"errorMessage":"Cannot upload — file not found: {path}","messagePattern":"Cannot upload — file not found: (.+?)","errorType":"exception","errorClass":"AtlasError","httpStatus":null,"severity":"error","filePath":"tools/atlas_client.py","lineNumber":198,"sourceCode":"    raise AtlasError(\n        f\"Prediction {prediction_id} did not finish within {timeout:.0f}s \"\n        f\"(last status: {last_status}). The job may still complete — \"\n        f\"check {PREDICTION_ENDPOINT}/{prediction_id}\"\n    )\n\n\ndef upload_media(file_path: str | Path, api_key: str, timeout: int = 120) -> str:\n    \"\"\"Upload a local file and return the hosted URL Atlas assigns to it.\n\n    Used to turn a local reference image into the `image_url` that image-to-video\n    models expect. Atlas has answered this endpoint with both {\"data\":\n    {\"download_url\": ...}} and a bare {\"url\": ...}, so both shapes are accepted.\n    \"\"\"\n    import requests\n\n    path = Path(file_path)\n    if not path.exists():\n        raise AtlasError(f\"Cannot upload — file not found: {path}\")\n\n    try:\n        with path.open(\"rb\") as handle:\n            response = requests.post(\n                UPLOAD_MEDIA_ENDPOINT,\n                headers=_headers(api_key, json_body=False),\n                files={\"file\": (path.name, handle)},\n                timeout=timeout,\n            )\n    except Exception as exc:  # noqa: BLE001\n        raise AtlasError(f\"Uploading {path.name} to Atlas Cloud failed: {exc}\") from exc\n\n    _raise_for_status(response, \"Atlas Cloud upload\")\n    data = _payload_of(response)\n\n    url = data.get(\"download_url\") or data.get(\"url\")\n    if not url:\n        raise AtlasError(f\"Atlas Cloud upload returned no URL: {str(data)[:500]}\")","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/atlas_client.py#L180-L216","documentation":"Raised by upload_media when the local file at file_path does not exist (Path.exists() is false) before any network activity starts. It is a precondition check so the caller gets a clear 'file not found' instead of an obscure open() traceback or a request with missing content. Causes include wrong path, race (file deleted/moved), or a relative path resolved against the wrong working directory.","triggerScenarios":"Passing a reference-image path that was never written (upstream generation step failed silently); file cleaned up by a temp-dir reaper between creation and upload; relative path resolved from a different cwd in a daemon or worker process.","commonSituations":"Pipeline stages assuming a prior stage's output exists without checking; path built with os.path.join on Windows using mixed separators; symlink targets deleted; files on unmounted network shares.","solutions":["Verify the upstream step that should have produced the file actually succeeded, and fail loudly there if not","Use absolute paths (Path(...).resolve()) before calling upload_media","If a temp file, ensure it isn't deleted (context manager exiting early) before upload runs","Check for stray whitespace/newlines in path strings from config or CLI args"],"exampleFix":"// before\nurl = atlas_client.upload_media(\"output/frame_001.png\", api_key)\n\n// after\nfrom pathlib import Path\np = Path(\"output/frame_001.png\").resolve()\nif not p.is_file():\n    raise FileNotFoundError(f\"reference image missing: {p}\")\nurl = atlas_client.upload_media(p, api_key)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\np = Path(file_path).resolve()\nif not p.is_file():\n    raise FileNotFoundError(f\"cannot upload missing file: {p}\")\nurl = atlas_client.upload_media(p, api_key)","typeGuard":"def is_uploadable_file(path) -> bool:\n    try:\n        return Path(path).is_file()\n    except OSError:\n        return False","tryCatchPattern":null,"preventionTips":["Resolve to absolute paths before calling upload","Make the producing stage's success a hard precondition for the upload stage","Strip whitespace from paths originating in config/CLI inputs"],"tags":["atlas-cloud","upload","filesystem","precondition","validation"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}