From b5b6788a3b4b03dd55c4993fbc62bd16cc5b3d7a Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 5 Nov 2015 15:28:59 +0100 Subject: [PATCH] Refactor error logging a bit Fix #286 --- vdirsyncer/cli/__init__.py | 11 ++++------- vdirsyncer/cli/config.py | 4 ++-- vdirsyncer/cli/utils.py | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/vdirsyncer/cli/__init__.py b/vdirsyncer/cli/__init__.py index 772c124..f795c0f 100644 --- a/vdirsyncer/cli/__init__.py +++ b/vdirsyncer/cli/__init__.py @@ -29,14 +29,11 @@ class CliError(RuntimeError): self.problems = problems RuntimeError.__init__(self, msg) - def format_cli(self): + def __str__(self): msg = self.msg.rstrip(u'.:') - if self.problems: - msg += u':' - if len(self.problems) == 1: - msg += u' {}'.format(self.problems[0]) - else: - msg += u'\n' + u'\n - '.join(self.problems) + u'\n\n' + li = u'\n - ' + for problem in self.problems or (): + msg += u'{}{}'.format(li, problem) return msg diff --git a/vdirsyncer/cli/config.py b/vdirsyncer/cli/config.py index 75ebd66..5f0252c 100644 --- a/vdirsyncer/cli/config.py +++ b/vdirsyncer/cli/config.py @@ -48,8 +48,8 @@ def _validate_general_section(general_config): .format(u', '.join(missing))) if problems: - raise CliError(u'Invalid general section. You should copy the example ' - u'config from the repository and edit it: {}\n' + raise CliError(u'Invalid general section. Copy the example ' + u'config from the repository and edit it: {}' .format(PROJECT_HOME), problems=problems) diff --git a/vdirsyncer/cli/utils.py b/vdirsyncer/cli/utils.py index 00980d0..406a9b6 100644 --- a/vdirsyncer/cli/utils.py +++ b/vdirsyncer/cli/utils.py @@ -78,7 +78,7 @@ def handle_cli_error(status_name=None): try: raise except CliError as e: - cli_logger.critical(e.format_cli()) + cli_logger.critical(e) except StorageEmpty as e: cli_logger.error( '{status_name}: Storage "{name}" was completely emptied. If you '