Commit 588a1919 authored by Alexandre's avatar Alexandre
Browse files

Catch exceptions

Fix regression inserted with 8cba1a31
parent d0836940
......@@ -219,7 +219,16 @@ def run_check_default(connection):
handle = connection.curl_handle
handle.prepare(handle, connection, request)
bundle = handle
connection.send_and_receive(bundle)
try:
connection.send_and_receive(bundle)
except (homer.ConnectionException, homer.DOHException) as e:
# GET and POST are mandatory and therefore if an error is caught
# here, print it and exit
if method == homer.DOH_GET or method == homer.DOH_POST:
error(e)
else:
print(e, file=sys.stderr)
return False
request.check_response(connection.debug)
if not print_result(connection, request, prefix=test_name, display_err=False):
if level >= opts.mandatory_level:
......@@ -248,7 +257,11 @@ def run_check_mime(connection, accept="application/dns-message", content_type="a
handle = connection.curl_handle
handle.setopt(pycurl.HTTPHEADER, header)
handle.prepare(handle, connection, request)
connection.send_and_receive(handle)
try:
connection.send_and_receive(handle)
except (homer.ConnectionException, homer.DOHException) as e:
print(e, file=sys.stderr)
return False
request.check_response(connection.debug)
if not print_result(connection, request, prefix=f"Test Header {', '.join(header)}"):
ok = False
......@@ -288,6 +301,9 @@ def run_check_trunc(connection):
# the RCODE set to FORMERR
# so response can not be parsed in this case
return ok
except homer.DOHException as e:
print(e, file=sys.stderr)
return False
if request.check_response(connection.debug): # FORMERR is expected
if connection.dot:
ok = request.rcode == dns.rcode.FORMERR
......@@ -565,7 +581,7 @@ def run_default(name, connection, opts):
if not opts.pipelining:
try:
connection.do_test(request, synchronous = not opts.multistreams)
except OpenSSL.SSL.Error as e:
except (OpenSSL.SSL.Error, homer.DOHException) as e:
ok = False
error(e)
break
......@@ -688,7 +704,7 @@ for ip in ip_set:
error("\"%s\" not a name or an IP address" % url)
except socket.gaierror:
error("Could not resolve \"%s\"" % url)
except homer.ConnectionException as e:
except (homer.ConnectionException, homer.DOHException) as e:
error(e)
if conn.dot and not conn.success:
ok = False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment