[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Provide a useful error message if we fail to load the inputfile
commit 7e4db43bc305d6dab716e5cb1f04a92388d58a34
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Tue Mar 25 17:14:40 2014 +0100
Provide a useful error message if we fail to load the inputfile
---
ooni/errors.py | 3 +++
ooni/nettest.py | 11 +++++++----
ooni/oonicli.py | 10 ++++++----
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/ooni/errors.py b/ooni/errors.py
index 4ee822e..3b62b2a 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -220,6 +220,9 @@ class InvalidOption(Exception):
class TaskTimedOut(Exception):
pass
+class InvalidInputFile(Exception):
+ pass
+
def get_error(error_key):
if error_key == 'test-helpers-key-missing':
return CouldNotFindTestHelper
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 4db7af2..aba768b 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -185,10 +185,13 @@ class NetTestLoader(object):
input_file['hash'] = m.group(2)
else:
input_file['filename'] = filename
- with open(filename) as f:
- h = sha256()
- for l in f:
- h.update(l)
+ try:
+ with open(filename) as f:
+ h = sha256()
+ for l in f:
+ h.update(l)
+ except:
+ raise e.InvalidInputFile(filename)
input_file['hash'] = h.hexdigest()
input_files.append(input_file)
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 5c3c0ce..6f4ebe0 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -181,7 +181,8 @@ def runWithDirector(logging=True, start_tor=True):
r = failure.trap(errors.TorNotRunning,
errors.InvalidOONIBCollectorAddress,
errors.UnableToLoadDeckInput, errors.CouldNotFindTestHelper,
- errors.CouldNotFindTestCollector, errors.ProbeIPUnknown)
+ errors.CouldNotFindTestCollector, errors.ProbeIPUnknown,
+ errors.InvalidInputFile)
if isinstance(failure.value, errors.TorNotRunning):
log.err("Tor does not appear to be running")
@@ -210,11 +211,12 @@ def runWithDirector(logging=True, start_tor=True):
log.err("Failed to lookup probe IP address.")
log.msg("Check your internet connection.")
+ elif isinstance(failure.value, errors.InvalidInputFile):
+ log.err("Invalid input file \"%s\"" % failure.value)
+
if config.advanced.debug:
log.exception(failure)
-
- reactor.stop()
-
+
# Wait until director has started up (including bootstrapping Tor)
# before adding tests
def post_director_start(_):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits