diff --git a/osc/babysitter.py b/osc/babysitter.py index 973580c2..43f31c17 100644 --- a/osc/babysitter.py +++ b/osc/babysitter.py @@ -151,7 +151,7 @@ def run(prg, argv=None): raise print(e, file=sys.stderr) except (oscerr.ConfigError, oscerr.NoConfigfile) as e: - print(e.msg, file=sys.stderr) + print(e, file=sys.stderr) except configparser.Error as e: print(e.message, file=sys.stderr) except oscerr.OscIOError as e: diff --git a/osc/credentials.py b/osc/credentials.py index bbae01c4..e27e5e58 100644 --- a/osc/credentials.py +++ b/osc/credentials.py @@ -15,6 +15,9 @@ try: except ImportError: gnomekeyring = None +from . import conf +from . import oscerr + class AbstractCredentialsManagerDescriptor(object): def name(self): @@ -184,7 +187,11 @@ class KeyringCredentialsManager(AbstractCredentialsManager): self._backend_cls_name = options def _load_backend(self): - keyring_backend = keyring.core.load_keyring(self._backend_cls_name) + try: + keyring_backend = keyring.core.load_keyring(self._backend_cls_name) + except ModuleNotFoundError: + msg = "Invalid credentials_mgr_class: {}".format(self._backend_cls_name) + raise oscerr.ConfigError(msg, conf.config['conffile']) keyring.set_keyring(keyring_backend) @classmethod diff --git a/osc/oscerr.py b/osc/oscerr.py index cd014839..e3ad9217 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -22,6 +22,9 @@ class ConfigError(OscBaseError): self.msg = msg self.file = fname + def __str__(self): + return "Error in config file {}\n {}".format(self.file, self.msg) + class ConfigMissingApiurl(ConfigError): """Exception raised when a apiurl does not exist in the config file""" def __init__(self, msg, fname, url): @@ -46,6 +49,9 @@ class NoConfigfile(OscBaseError): self.file = fname self.msg = msg + def __str__(self): + return "Config file cannot be found: {}\n {}".format(self.file, self.msg) + class ExtRuntimeError(OscBaseError): """Exception raised when there is a runtime error of an external tool""" def __init__(self, msg, fname):