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

Improve upload error output #6043

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
3 changes: 2 additions & 1 deletion src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class UploadError(Exception):
def __init__(self, error: ConnectionError | HTTPError | str) -> None:
if isinstance(error, HTTPError):
message = (
f"HTTP Error {error.response.status_code}: {error.response.reason}"
f"HTTP Error {error.response.status_code}: {error.response.reason} |"
f" {error.response.content!r}"
)
elif isinstance(error, ConnectionError):
message = (
Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_publish_returns_non_zero_code_for_upload_errors(
Publishing simple-project (1.2.3) to PyPI
"""
expected_error_output = """\
HTTP Error 400: Bad Request
HTTP Error 400: Bad Request | b'Bad Request'
"""

assert expected_output in app_tester.io.fetch_output()
Expand Down
23 changes: 21 additions & 2 deletions tests/publishing/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_uploader_properly_handles_400_errors(
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")

assert str(e.value) == "HTTP Error 400: Bad Request"
assert str(e.value) == "HTTP Error 400: Bad Request | b'Bad request'"


def test_uploader_properly_handles_403_errors(
Expand All @@ -43,7 +43,26 @@ def test_uploader_properly_handles_403_errors(
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")

assert str(e.value) == "HTTP Error 403: Forbidden"
assert str(e.value) == "HTTP Error 403: Forbidden | b'Unauthorized'"


def test_uploader_properly_handles_nonstandard_errors(
http: type[httpretty.httpretty], uploader: Uploader
):
# content based off a true story.
# Message changed to protect the ~~innocent~~ guilty.
content = (
b'{\n "errors": [ {\n '
b'"status": 400,'
b'"message": "I cant let you do that, dave"\n'
b"} ]\n}"
)
http.register_uri(http.POST, "https://foo.com", status=400, body=content)

with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")

assert str(e.value) == f"HTTP Error 400: Bad Request | {content}"


def test_uploader_properly_handles_301_redirects(
Expand Down