From 7f8adad313999775992396fc39f6ccb5bdfd5af4 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Wed, 4 Feb 2015 10:34:43 -0800 Subject: [PATCH] Print info about request on error This can help in diagnosing certain issues. For example, if I were trying to use a "http+unix" URL but I don't have #299, then I'll get the following: [marca@marca-mac2 httpie]$ http http+unix://%2Ftmp%2Fprofilesvc.sock/status/pid http: error: ConnectionError: ('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known')) while doing GET request to URL: http://http+unix//%2Ftmp%2Fprofilesvc.sock/status/pid Having the URL in the error message is super useful here so that I know an extra `http://` is getting prepended and it's not doing what I expected. --- httpie/core.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/httpie/core.py b/httpie/core.py index 95f53abd..83910ec7 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -183,7 +183,13 @@ def main(args=sys.argv[1:], env=Environment()): # Network errors vs. bugs, etc. if traceback: raise - error('%s: %s', type(e).__name__, str(e)) + msg = str(e) + if hasattr(e, 'request'): + request = e.request + if hasattr(request, 'url'): + msg += ' while doing %s request to URL: %s' % ( + request.method, request.url) + error('%s: %s', type(e).__name__, msg) exit_status = ExitStatus.ERROR finally: