Duke-GCB / Duke-GCB/datadelivery-cli

Catch connection errors and improve error messages

Open
#5 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

I had a stale configuration my `~/.datadelivery.yml` file, pointing to a URL that's not live:

```
url: http://127.0.0.1:8000/api/v2/
```

When I tried to run a deliver command, I get the following:

```
$ datadelivery deliver -b sample --email john.bradley@duke.edu
Traceback (most recent call last):
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/connection.py", line 83, in create_connection
raise err
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 166, in connect
conn = self._new_conn()
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/adapters.py", line 440, in send
timeout=timeout
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/v2/s3-endpoints/?name=default (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 61] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/dcl9/Code/python/datadelivery-cli/venv/bin/datadelivery", line 11, in
load_entry_point('datadelivery==0.0.1', 'console_scripts', 'datadelivery')()
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/__main__.py", line 14, in main
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/argparser.py", line 26, in parse_and_run_commands
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/argparser.py", line 73, in _run_deliver
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/commands.py", line 24, in deliver
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/commands.py", line 14, in _create_s3
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/s3.py", line 11, in __init__
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/s3.py", line 62, in _get_current_endpoint
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/datadelivery-0.0.1-py3.6.egg/datadelivery/s3.py", line 27, in _get_request
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/Users/dcl9/Code/python/datadelivery-cli/venv/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/v2/s3-endpoints/?name=default (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 61] Connection refused',))
$
```

While we don't expect end-users to override their API url here, HTTP connection errors should be expected and relayed more succintcly :)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.