diff options
Diffstat (limited to 'src/leap/bitmask')
-rwxr-xr-x | src/leap/bitmask/cli/bitmask_cli.py | 30 | ||||
-rw-r--r-- | src/leap/bitmask/cli/vpn.py | 5 | ||||
-rw-r--r-- | src/leap/bitmask/core/dispatcher.py | 1 |
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 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] diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py index c026c49..9d48600 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: |