From 500de6f081963236851663757bdb3dbfed07362e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 24 Jan 2015 16:38:01 +0100 Subject: [PATCH] Improve internal apis --- vdirsyncer/cli/__init__.py | 4 ++-- vdirsyncer/cli/tasks.py | 4 ++-- vdirsyncer/cli/utils.py | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 17970f0..68d913c 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -16,8 +16,8 @@ def catch_errors(f): try: f(*a, **kw) except: - if not handle_cli_error(): - sys.exit(1) + handle_cli_error() + sys.exit(1) return inner diff --git a/vdirsyncer/cli/tasks.py b/vdirsyncer/cli/tasks.py index 20960b8..ebfefab 100644 --- a/vdirsyncer/cli/tasks.py +++ b/vdirsyncer/cli/tasks.py @@ -70,8 +70,8 @@ def sync_collection(wq, pair_name, collection, config_a, config_b, force_delete=force_delete ) except: - if not handle_cli_error(status_name): - raise JobFailed() + handle_cli_error(status_name) + raise JobFailed() save_status(general['status_path'], pair_name, collection, data_type='items', data=status) diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index af7e735..7e7b29e 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -44,6 +44,13 @@ class JobFailed(RuntimeError): def handle_cli_error(status_name='sync'): + ''' + Print a useful error message for the current exception. + + This is supposed to catch all exceptions, and should never raise any + exceptions itself. + ''' + try: raise except CliError as e: @@ -480,8 +487,8 @@ class WorkerQueue(object): try: func(wq=self) except Exception as e: - if not _handle_cli_error(): - self._exceptions.append(e) + _handle_cli_error() + self._exceptions.append(e) finally: self._queue.task_done()