Refactor error logging a bit

Fix #286
This commit is contained in:
Markus Unterwaditzer 2015-11-05 15:28:59 +01:00
parent 0f5bce333e
commit b5b6788a3b
3 changed files with 7 additions and 10 deletions

View file

@ -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

View file

@ -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)

View file

@ -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 '