summaryrefslogtreecommitdiff
path: root/src/leap/bitmask
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-04-14 20:01:52 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-19 20:14:23 +0200
commite57ed0cd5ba92220e09fe80ab04cce0b3cccfaeb (patch)
tree68958aee61db4d8906d8b97a3603929d55a24fb6 /src/leap/bitmask
parent9c1eec5551f13306d1745bbb77502c5eba9955a1 (diff)
[bug] improve exception catching in execution loop
Diffstat (limited to 'src/leap/bitmask')
-rwxr-xr-xsrc/leap/bitmask/cli/bitmask_cli.py30
-rw-r--r--src/leap/bitmask/cli/vpn.py5
-rw-r--r--src/leap/bitmask/core/dispatcher.py1
3 files changed, 27 insertions, 9 deletions
diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py
index ef76cb47..f138e486 100755
--- a/src/leap/bitmask/cli/bitmask_cli.py
+++ b/src/leap/bitmask/cli/bitmask_cli.py
@@ -21,6 +21,7 @@ Bitmask Command Line interface: zmq client.
import json
import sys
import signal
+import traceback
from colorama import Fore
from twisted.internet import reactor, defer
@@ -142,11 +143,15 @@ def execute():
cli = BitmaskCLI(cfg)
cli.data = ['core', 'version']
args = None if '--noverbose' in sys.argv else ['--verbose']
- yield cli._send(
- timeout=0.1, printer=_null_printer,
- errb=lambda: cli.start(args))
- if 'start' in sys.argv or 'restart' in sys.argv:
- command.default_dict_printer({'start': 'ok'})
+
+ try:
+ yield cli._send(
+ timeout=0.1, printer=_null_printer,
+ errb=lambda: cli.start(args))
+ except Exception, e:
+ print (Fore.RED + "ERROR: " + Fore.RESET +
+ "%s" % e.strerror)
+ defer.returnValue('')
cli.data = []
cli.print_json = print_json
@@ -154,11 +159,19 @@ def execute():
if print_json:
args.remove('--json')
- yield cli.execute(args)
try:
+ yield cli.execute(args)
+ if 'start' in sys.argv or 'restart' in sys.argv:
+ command.default_dict_printer({'start': 'ok'})
+ except Exception, e:
+ if hasattr(e, 'strerror'):
+ print (Fore.RED + "ERROR: " + Fore.RESET +
+ "%s" % e.strerror)
+ else:
+ if not hasattr(e, 'expected'):
+ print traceback.format_exc()
+ finally:
yield reactor.stop()
- except:
- pass
def _null_printer(*args):
@@ -166,6 +179,7 @@ def _null_printer(*args):
def main():
+
def signal_handler(signal, frame):
if reactor.running:
reactor.stop()
diff --git a/src/leap/bitmask/cli/vpn.py b/src/leap/bitmask/cli/vpn.py
index 60c57aac..0c5eddec 100644
--- a/src/leap/bitmask/cli/vpn.py
+++ b/src/leap/bitmask/cli/vpn.py
@@ -62,7 +62,10 @@ SUBCOMMANDS:
try:
_, provider = uid.split('@')
except ValueError:
- raise ValueError("A provider is needed to start the VPN")
+ error = ValueError()
+ error.strerror = "A provider is needed to start the VPN"
+ error.expected = True
+ raise error
self.data += ['start', provider]
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index c026c490..9d486009 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -541,6 +541,7 @@ def _format_error(failure):
# If a exception declares the 'expected' attribute as True,
# we will not print a full traceback
+
expected = getattr(failure.value, 'expected', False)
if not expected:
try: