1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-09 22:36:14 +01:00

Merge branch 'improve_URLError_msg' of https://github.com/marcus-h/osc

Improve error message in case of an URLError.
This commit is contained in:
Marcus Huewe 2021-10-11 16:03:26 +02:00
commit 26aea786da
2 changed files with 10 additions and 3 deletions

View File

@ -139,7 +139,11 @@ def run(prg, argv=None):
except HTTPException as e:
print(e, file=sys.stderr)
except URLError as e:
print('Failed to reach a server:\n', e.reason, file=sys.stderr)
msg = 'Failed to reach a server'
if hasattr(e, '_osc_host_port'):
msg += ' (%s)' % e._osc_host_port
msg += ':\n'
print(msg, e.reason, file=sys.stderr)
except IOError as e:
# ignore broken pipe
if e.errno != errno.EPIPE:

View File

@ -33,7 +33,7 @@ except ImportError:
try:
from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote
from urllib.error import HTTPError
from urllib.error import HTTPError, URLError
from urllib.request import pathname2url, install_opener, urlopen
from urllib.request import Request as URLRequest
from io import StringIO
@ -42,7 +42,7 @@ except ImportError:
#python 2.x
from urlparse import urlsplit, urlunsplit, urlparse
from urllib import pathname2url, quote_plus, urlencode, unquote
from urllib2 import HTTPError, install_opener, urlopen
from urllib2 import HTTPError, URLError, install_opener, urlopen
from urllib2 import Request as URLRequest
from cStringIO import StringIO
from httplib import IncompleteRead
@ -3402,6 +3402,9 @@ def http_request(method, url, headers={}, data=None, file=None):
req.add_header('Content-Length', str(content_length))
try:
return urlopen(req)
except URLError as e:
e._osc_host_port = req.host
raise
finally:
if hasattr(conf.cookiejar, 'save'):
conf.cookiejar.save(ignore_discard=True)