Fix error messages for unknown fetchparam strategy

See #326
This commit is contained in:
Markus Unterwaditzer 2016-01-30 18:51:26 +01:00
parent 6c7b6f47b1
commit d30b4752db
2 changed files with 13 additions and 2 deletions

View file

@ -186,7 +186,7 @@ class Config(object):
def get_storage_args(self, storage_name, pair_name=None):
try:
return expand_fetch_params(self.storages[storage_name])
args = self.storages[storage_name]
except KeyError:
pair_pref = 'Pair {}: '.format(pair_name) if pair_name else ''
raise CliError(
@ -194,6 +194,8 @@ class Config(object):
'These are the configured storages: {}'
.format(pair_pref, storage_name, list(self.storages))
)
else:
return expand_fetch_params(args)
def get_pair(self, pair_name):
return PairConfig(self, pair_name, *self.pairs[pair_name])

View file

@ -51,10 +51,19 @@ def _fetch_value(opts, key):
return rv
strategy = opts[0]
try:
strategy_fn = STRATEGIES[strategy]
except KeyError:
if strategy == 'keyring':
raise exceptions.UserError(
'Fetching passwords via keyring is deprecated. See the '
'changelog for migration paths.')
raise exceptions.UserError('Unknown strategy: {}'.format(strategy))
logger.debug('Fetching value for {} with {} strategy.'
.format(key, strategy))
try:
rv = STRATEGIES[strategy](*opts[1:])
rv = strategy_fn(*opts[1:])
except (click.Abort, KeyboardInterrupt) as e:
password_cache[cache_key] = e
raise