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

Fix: Informative UploadError #7004

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

moonsikpark
Copy link
Contributor

@moonsikpark moonsikpark commented Nov 11, 2022

Pull Request Check List

Resolves: #3813

  • Added tests for changed code.
  • Updated documentation for changed code.

When UploadError is raised due to requests.ConnectionError, the error message is a fixed general recommendation. The error itself is not shown to the user, making it hard for the user to debug the problem.

(env) user@machine test % poetry publish

Publishing test (0.0.0) to PyPI
 - Uploading test-0.0.0-py3-none-any.whl FAILED

Connection Error: We were unable to connect to the repository, ensure the url is correct and can be reached.

This PR fixes the problem by adding the representation of the exception to the error message.

(env) user@machine test % sudo poetry publish

Publishing test (0.0.0) to PyPI
 - Uploading test-0.0.0-py3-none-any.whl FAILED

Connection Error: We were unable to connect to the repository due to HTTPSConnectionPool(host='upload.pypi.org', port=443): Max retries exceeded with url: /legacy/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10670dcd0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')).

Copy link
Member

@neersighted neersighted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see this use exception chaining instead of doubling down on string-based handling.

@moonsikpark
Copy link
Contributor Author

moonsikpark commented Nov 11, 2022

@neersighted I am not clear on what you want by using exception chaining. I've brought some examples of libraries by pypa to observe actions in case of network failure. Are you saying you want twine-style of showing every stack traces related to it? Or you just want pip-style but want to use the from statement and __cause__ attribute of exception chaining?

pip

(env) user@machine test % pip install requests
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x104133b10>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/requests/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x1020e8a50>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/requests/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x1041394d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/requests/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x104139dd0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/requests/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x10413a810>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')': /simple/requests/
ERROR: Could not find a version that satisfies the requirement requests (from versions: none)
ERROR: No matching distribution found for requests

twine

(env) user@machine test % twine upload dist/* -u token -p pypi-test  
Uploading distributions to https://upload.pypi.org/legacy/
Uploading test-1.0.0-py3-none-any.whl
WARNING  Retrying (Retry(total=9, connect=4, read=None, redirect=None, status=None)) after connection broken by                        
         'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10641a710>: Failed to establish a new connection: [Errno 
         8] nodename nor servname provided, or not known')': /legacy/                                                                  
WARNING  Retrying (Retry(total=8, connect=3, read=None, redirect=None, status=None)) after connection broken by                        
         'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10641aad0>: Failed to establish a new connection: [Errno 
         8] nodename nor servname provided, or not known')': /legacy/                                                                  
WARNING  Retrying (Retry(total=7, connect=2, read=None, redirect=None, status=None)) after connection broken by                        
         'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x106419050>: Failed to establish a new connection: [Errno 
         8] nodename nor servname provided, or not known')': /legacy/                                                                  
WARNING  Retrying (Retry(total=6, connect=1, read=None, redirect=None, status=None)) after connection broken by                        
         'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10642d8d0>: Failed to establish a new connection: [Errno 
         8] nodename nor servname provided, or not known')': /legacy/                                                                  
WARNING  Retrying (Retry(total=5, connect=0, read=None, redirect=None, status=None)) after connection broken by                        
         'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x106431b10>: Failed to establish a new connection: [Errno 
         8] nodename nor servname provided, or not known')': /legacy/                                                                  
  0% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/230.5 kB • --:-- • ?
Traceback (most recent call last):
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 961, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x1064328d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 815, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 815, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 815, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  [Previous line repeated 2 more times]
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='upload.pypi.org', port=443): Max retries exceeded with url: /legacy/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x1064328d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Workspace/poetry/env/bin/twine", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/twine/__main__.py", line 33, in main
    error = cli.dispatch(sys.argv[1:])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/twine/cli.py", line 123, in dispatch
    return main(args.args)
           ^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/twine/commands/upload.py", line 198, in main
    return upload(upload_settings, parsed_args.dists)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/twine/commands/upload.py", line 142, in upload
    resp = repository.upload(package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/twine/repository.py", line 186, in upload
    resp = self._upload(package)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/twine/repository.py", line 172, in _upload
    resp = self.session.post(
           ^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/Workspace/poetry/env/lib/python3.11/site-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='upload.pypi.org', port=443): Max retries exceeded with url: /legacy/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x1064328d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

@thomasuster
Copy link

Let's merge this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make more informative error messages when UploadError
4 participants