diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2017-04-14 20:01:52 +0200 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2017-04-19 20:14:23 +0200 |
commit | e57ed0cd5ba92220e09fe80ab04cce0b3cccfaeb (patch) | |
tree | 68958aee61db4d8906d8b97a3603929d55a24fb6 /src/leap/bitmask/cli | |
parent | 9c1eec5551f13306d1745bbb77502c5eba9955a1 (diff) |
[bug] improve exception catching in execution loop
Diffstat (limited to 'src/leap/bitmask/cli')
-rwxr-xr-x | src/leap/bitmask/cli/bitmask_cli.py | 30 | ||||
-rw-r--r-- | src/leap/bitmask/cli/vpn.py | 5 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py index ef76cb4..f138e48 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 60c57aa..0c5edde 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] |