Skip to content

Commit

Permalink
Report a config error when trying to load credentials_mgr_class that …
Browse files Browse the repository at this point in the history
…does't exist
  • Loading branch information
dmach committed Mar 28, 2022
1 parent 8a85789 commit 90a1cb8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion osc/babysitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion osc/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
except ImportError:
gnomekeyring = None

from . import conf
from . import oscerr


class AbstractCredentialsManagerDescriptor(object):
def name(self):
Expand Down Expand Up @@ -184,7 +187,11 @@ def _process_options(self, options):
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
Expand Down
6 changes: 6 additions & 0 deletions osc/oscerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def __init__(self, msg, fname):
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):
Expand All @@ -46,6 +49,9 @@ def __init__(self, fname, msg):
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):
Expand Down

0 comments on commit 90a1cb8

Please sign in to comment.