Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better errors on upload failure #9701

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from poetry.core.masonry.metadata import Metadata
from poetry.core.masonry.utils.helpers import distribution_name
from requests.exceptions import ConnectionError
from requests.exceptions import HTTPError
from requests_toolbelt import user_agent
from requests_toolbelt.multipart import MultipartEncoder
from requests_toolbelt.multipart import MultipartEncoderMonitor
Expand All @@ -27,23 +25,7 @@


class UploadError(Exception):
def __init__(self, error: ConnectionError | HTTPError | str) -> None:
if isinstance(error, HTTPError):
if error.response is None:
message = "HTTP Error connecting to the repository"
else:
message = (
f"HTTP Error {error.response.status_code}: "
f"{error.response.reason} | {error.response.content!r}"
)
elif isinstance(error, ConnectionError):
message = (
"Connection Error: We were unable to connect to the repository, "
"ensure the url is correct and can be reached."
)
else:
message = error
super().__init__(message)
pass


class Uploader:
Expand Down Expand Up @@ -268,12 +250,22 @@ def _upload_file(
bar.display()
else:
resp.raise_for_status()
except (requests.ConnectionError, requests.HTTPError) as e:

except requests.RequestException as e:
if self._io.output.is_decorated():
self._io.overwrite(
f" - Uploading <c1>{file.name}</c1> <error>FAILED</>"
)
raise UploadError(e)

if e.response is not None:
message = (
f"HTTP Error {e.response.status_code}: "
f"{e.response.reason} | {e.response.content!r}"
)
raise UploadError(message) from e

raise UploadError("Error connecting to repository") from e

finally:
self._io.write_line("")

Expand Down
5 changes: 1 addition & 4 deletions tests/console/commands/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import requests

from poetry.factory import Factory
from poetry.publishing.uploader import UploadError


if TYPE_CHECKING:
Expand Down Expand Up @@ -82,9 +81,7 @@ def request_callback(*_: Any, **__: Any) -> None:

assert exit_code == 1

expected = str(UploadError(error=requests.ConnectionError()))

assert expected in app_tester.io.fetch_error()
assert "Error connecting to repository" in app_tester.io.fetch_error()


def test_publish_with_cert(
Expand Down
Loading