[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Make reporter creation more robust



commit e620ea035144550e3ca4162a25237367919045cb
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Wed Mar 13 20:57:44 2013 +0100

    Make reporter creation more robust
    
    We want to raise errors by yielding, because we are inside of a inlineCallbacks
    decorated function.
---
 ooni/reporter.py |   12 +++++++-----
 ooni/runner.py   |    2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/ooni/reporter.py b/ooni/reporter.py
index 594c6b8..20193c9 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -226,6 +226,7 @@ class YAMLReporter(OReporter):
 
         self.writeReportEntry(self.testDetails)
         self.created.callback(self)
+        return defer.succeed(None)
 
     def finish(self):
         self._stream.close()
@@ -305,7 +306,7 @@ class OONIBReporter(OReporter):
             self.agent = Agent(reactor, sockshost="127.0.0.1",
                 socksport=int(config.tor.socks_port))
         except Exception, e:
-            log.exception(e)
+            yield defer.fail(e)
 
         url = self.collectorAddress + '/report'
 
@@ -338,11 +339,11 @@ class OONIBReporter(OReporter):
                                 bodyProducer=bodyProducer)
         except ConnectionRefusedError:
             log.err("Connection to reporting backend failed (ConnectionRefusedError)")
-            raise OONIBReportCreationError
+            self.created.errback(defer.fail(OONIBReportCreationError))
 
         except Exception, e:
             log.exception(e)
-            raise OONIBReportCreationError
+            yield defer.fail(OONIBReportCreationError)
 
         # This is a little trix to allow us to unspool the response. We create
         # a deferred and call yield on it.
@@ -355,7 +356,7 @@ class OONIBReporter(OReporter):
             parsed_response = json.loads(backend_response)
         except Exception, e:
             log.exception(e)
-            raise OONIBReportCreationError
+            yield defer.fail(e)
 
         self.reportID = parsed_response['report_id']
         self.backendVersion = parsed_response['backend_version']
@@ -392,7 +393,8 @@ class Report(object):
         """
         l = []
         for reporter in self.reporters[:]:
-            reporter.createReport()
+            d = reporter.createReport()
+            d.addErrback(self.failedOpeningReport, reporter)
             reporter.created.addErrback(self.failedOpeningReport, reporter)
             l.append(reporter.created)
         log.debug("Reporters created: %s" % l)
diff --git a/ooni/runner.py b/ooni/runner.py
index 080db18..abdc256 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -15,7 +15,7 @@ from ooni.reporter import OONIBReporter, YAMLReporter, OONIBReportError
 from ooni.inputunit import InputUnitFactory
 from ooni.nettest import NetTestCase, NoPostProcessor
 from ooni.utils import log, checkForRoot, pushFilenameStack
-from ooni.utils import NotRootError, Storage
+from ooni.utils import Storage
 from ooni.utils.net import randomFreePort
 
 class InvalidResumeFile(Exception):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits