[tor-commits] [ooni-probe/master] Better error handling in reporter

art at torproject.org art at torproject.org
Wed Nov 21 15:36:20 UTC 2012


commit b243272496665e9d55929bd9c2f5015e0565fc56
Author: Arturo Filastò <art at fuffa.org>
Date:   Wed Nov 21 11:25:51 2012 +0100

    Better error handling in reporter
    * Notify the user when the connection has failed because the backend was not reachable
---
 nettests/core/http_host.py |    2 +-
 ooni/reporter.py           |   12 ++++++++----
 ooni/runner.py             |   19 ++++++++++++++++---
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/nettests/core/http_host.py b/nettests/core/http_host.py
index 3912dfc..3ebfd04 100644
--- a/nettests/core/http_host.py
+++ b/nettests/core/http_host.py
@@ -35,7 +35,7 @@ class HTTPHost(httpt.HTTPTest):
 
     usageOptions = UsageOptions
 
-    inputFile = ['file', 'f', None, 
+    inputFile = ['file', 'f', None,
             'List of hostnames to test for censorship']
 
     requiredOptions = ['backend']
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 5006a21..0110b02 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -18,6 +18,7 @@ import traceback
 from twisted.python.util import untilConcludes
 from twisted.trial import reporter
 from twisted.internet import defer, reactor
+from twisted.internet.error import ConnectionRefusedError
 
 from ooni.templates.httpt import BodyReceiver, StringProducer
 from ooni.utils import otime, log, geodata
@@ -204,18 +205,18 @@ class OONIBReporter(OReporter):
         request = {'report_id': self.report_id,
                 'content': content}
 
-        log.debug("Updating report with id %s" % self.report_id)
+        log.debug("Updating report with id %s (%s)" % (self.report_id, url))
         request_json = json.dumps(request)
         log.debug("Sending %s" % request_json)
 
         bodyProducer = StringProducer(json.dumps(request))
-        log.debug("Creating report via url %s" % url)
 
         try:
             response = yield self.agent.request("PUT", url, 
                                 bodyProducer=bodyProducer)
         except:
             # XXX we must trap this in the runner and make sure to report the data later.
+            log.err("Error in writing report entry")
             raise OONIBReportUpdateFailed
 
         #parsed_response = json.loads(backend_response)
@@ -254,12 +255,15 @@ class OONIBReporter(OReporter):
         log.debug("Sending %s" % request_json)
 
         bodyProducer = StringProducer(json.dumps(request))
-        log.debug("Creating report via url %s" % url)
 
         try:
             response = yield self.agent.request("POST", url, 
                                 bodyProducer=bodyProducer)
-        except:
+        except ConnectionRefusedError:
+            log.err("Connection to reporting backend failed (ConnectionRefusedError)")
+            raise OONIBReportCreationFailed
+        except Exception, e:
+            log.exception(e)
             raise OONIBReportCreationFailed
 
         # This is a little trix to allow us to unspool the response. We create
diff --git a/ooni/runner.py b/ooni/runner.py
index 536ecfe..8edf857 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -207,18 +207,31 @@ def runTestCases(test_cases, options,
             log.msg("options[0] = %s" % first)
             test_inputs = [None]
 
-    reportFile = open(yamloo_filename, 'w+')
+    log.debug("Creating %s" % yamloo_filename)
 
     if cmd_line_options['collector']:
+        log.debug("Using remote collector %s" % cmd_line_options['collector'])
         oreporter = reporter.OONIBReporter(cmd_line_options['collector'])
     else:
+        reportFile = open(yamloo_filename, 'w+')
+        log.debug("Reporting to file %s" % reportFile)
         oreporter = reporter.YAMLReporter(reportFile)
 
-    input_unit_factory = InputUnitFactory(test_inputs)
+    try:
+        input_unit_factory = InputUnitFactory(test_inputs)
+    except Exception, e:
+        log.exception(e)
 
     log.debug("Creating report")
 
-    yield oreporter.createReport(options)
+    try:
+        yield oreporter.createReport(options)
+    except reporter.OONIBReportCreationFailed:
+        log.err("Error in creating new report")
+        reactor.stop()
+        raise
+    except Exception, e:
+        log.exception(e)
 
     # This deferred list is a deferred list of deferred lists
     # it is used to store all the deferreds of the tests that





More information about the tor-commits mailing list