Skip to content

Commit

Permalink
Improve upload error output (#6043)
Browse files Browse the repository at this point in the history
* Improve information returned from upload errors
* Fix the tests to for new behavior, add one for this specific case
  • Loading branch information
theunkn0wn1 authored Jul 24, 2022
1 parent 3e60aed commit 95915f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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

0 comments on commit 95915f0

Please sign in to comment.