From: Michael Tremer Date: Thu, 2 Nov 2017 15:24:06 +0000 (+0100) Subject: cli: Catch dependency errors and show a nice message X-Git-Tag: 0.9.28~1285^2~1325 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=271607345a8d5bec8b7885cd1d15b14ce0dd08d9;p=pakfire.git cli: Catch dependency errors and show a nice message Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index 635d0d0bb..9a63cace9 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -219,6 +219,26 @@ class Cli(object): return 128 + signal.SIGINT + except DependencyError as e: + self.ui.message(_("One or more dependencies could not been resolved")) + self.ui.message("") # empty line + + # This exception provides a list of all problems + problems, = e.args + + # List all problems + for problem in problems: + self.ui.message(" * %s" % problem) + + self.ui.message(" %s" % _("Possible solutions are:")) + for solution in problem.solutions: + self.ui.message(" * %s" % solution) + + # Add another empty line + self.ui.message("") + + return 4 + # Catch all errors and show a user-friendly error message. except Error as e: self.ui.message(_("An error has occured when running Pakfire"), level=logging.CRITICAL) diff --git a/src/pakfire/errors.py b/src/pakfire/errors.py index 6524638c1..02ea8fa47 100644 --- a/src/pakfire/errors.py +++ b/src/pakfire/errors.py @@ -21,6 +21,8 @@ from .i18n import _ +from ._pakfire import DependencyError + class commandTimeoutExpired(Exception): pass # XXX cannot be as is @@ -52,34 +54,6 @@ class ConfigError(Error): class DatabaseError(Error): pass -class DependencyError(Error): - exit_code = 4 - - def __init__(self, request): - Error.__init__(self) - - # Request object that could not be solved - self.request = request - - @property - def message(self): - lines = [ - _("One or more dependencies could not been resolved"), - "", # empty line - ] - - for problem in self.request.problems: - lines.append("%s" % problem) - - lines.append(_("Possible solutions are:")) - for solution in problem.solutions: - lines.append(" %s" % solution) - - # Add another empty line - lines.append("") - - return "\n".join(lines) - class DownloadError(Error): message = _("An error occured when pakfire tried to download files.")