commit 578e645233ed12ae26fb2b6b2f1af309ae5398df Author: Arturo Filastò art@fuffa.org Date: Fri Mar 27 11:30:33 2015 +0100
Handle also unhandled exceptions inside of ooni(deckgen|report|resources)
* Exit with the correct exit status --- bin/oonideckgen | 4 +++- bin/oonireport | 4 +++- bin/ooniresources | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/bin/oonideckgen b/bin/oonideckgen index a761349..f4dd392 100755 --- a/bin/oonideckgen +++ b/bin/oonideckgen @@ -1,4 +1,5 @@ #!/usr/bin/env python +import sys import exceptions
from twisted.internet import defer, reactor @@ -10,7 +11,8 @@ exitCode = 128 def failed(failure): global exitCode
- r = failure.trap(exceptions.SystemExit) + r = failure.trap(exceptions.SystemExit, + Exception) if r != exceptions.SystemExit: log.err("Failed to run oonideckgen") log.exception(failure) diff --git a/bin/oonireport b/bin/oonireport index ee9a214..38fd5a7 100755 --- a/bin/oonireport +++ b/bin/oonireport @@ -1,4 +1,5 @@ #!/usr/bin/env python +import sys from twisted.internet import defer, reactor
from ooni.utils import log @@ -9,7 +10,8 @@ exitCode = 128 def failed(failure): global exitCode
- r = failure.trap(exceptions.SystemExit) + r = failure.trap(exceptions.SystemExit, + Exception) if r != exceptions.SystemExit: log.err("Failed to run oonideckgen") log.exception(failure) diff --git a/bin/ooniresources b/bin/ooniresources index 1960a1d..6913bb4 100755 --- a/bin/ooniresources +++ b/bin/ooniresources @@ -1,15 +1,28 @@ #!/usr/bin/env python +import sys from twisted.internet import defer, reactor
from ooni.utils import log from ooni.resources import cli
+exitCode = 128 def failed(failure): - log.err("Failed to run ooniresources") - log.exception(failure) + global exitCode + + r = failure.trap(exceptions.SystemExit, + Exception) + if r != exceptions.SystemExit: + log.err("Failed to run ooniresources") + log.exception(failure) + exitCode = 127 + else: + exitCode = failure.value.code reactor.stop()
def done(result): + global exitCode + + exitCode = 0 reactor.stop()
def start(): @@ -19,3 +32,4 @@ def start():
reactor.callWhenRunning(start) reactor.run() +sys.exit(exitCode)
tor-commits@lists.torproject.org