diff --git a/src/poetry/publishing/uploader.py b/src/poetry/publishing/uploader.py index 8de42e9cebb..ffa2adde6cb 100644 --- a/src/poetry/publishing/uploader.py +++ b/src/poetry/publishing/uploader.py @@ -212,7 +212,6 @@ def _upload( self, session: requests.Session, url: str, dry_run: Optional[bool] = False ) -> None: for file in self.files: - # TODO: Check existence self._upload_file(session, url, file, dry_run) @@ -225,6 +224,9 @@ def _upload_file( ) -> None: from cleo.ui.progress_bar import ProgressBar + if not file.is_file(): + raise UploadError(f"Archive ({file}) does not exist") + data = self.post_data(file) data.update( { diff --git a/tests/publishing/test_uploader.py b/tests/publishing/test_uploader.py index e4deb372884..f129be230cb 100644 --- a/tests/publishing/test_uploader.py +++ b/tests/publishing/test_uploader.py @@ -60,3 +60,12 @@ def test_uploader_registers_for_appropriate_400_errors(mocker, http, uploader): uploader.upload("https://foo.com") assert 1 == register.call_count + + +def test_uploader_properly_handles_file_not_existing(mocker, http, uploader): + mocker.patch("pathlib.Path.is_file", return_value=False) + + with pytest.raises(UploadError) as e: + uploader.upload("https://foo.com") + + assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)