mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #51097 from terminalmage/fix-keyerror-raise
Fix improper exception raises (2018.3)
This commit is contained in:
commit
b19c990a16
@ -1704,7 +1704,7 @@ class LazyLoader(salt.utils.lazy.LazyDict):
|
||||
if not isinstance(key, six.string_types):
|
||||
raise KeyError('The key must be a string.')
|
||||
if '.' not in key:
|
||||
raise KeyError('The key \'%s\' should contain a \'.\'', key)
|
||||
raise KeyError('The key \'{0}\' should contain a \'.\''.format(key))
|
||||
mod_name, _ = key.split('.', 1)
|
||||
with self._lock:
|
||||
# It is possible that the key is in the dictionary after
|
||||
|
@ -135,9 +135,7 @@ def setup_handlers():
|
||||
transport_registry = TransportRegistry(default_transports)
|
||||
url = urlparse(dsn)
|
||||
if not transport_registry.supported_scheme(url.scheme):
|
||||
raise ValueError(
|
||||
'Unsupported Sentry DSN scheme: %s', url.scheme
|
||||
)
|
||||
raise ValueError('Unsupported Sentry DSN scheme: {0}'.format(url.scheme))
|
||||
except ValueError as exc:
|
||||
log.info(
|
||||
'Raven failed to parse the configuration provided DSN: %s', exc
|
||||
|
@ -412,7 +412,7 @@ def create_snapshot(config='root', snapshot_type='single', pre_number=None,
|
||||
cleanup_algorithm, userdata)
|
||||
else:
|
||||
raise CommandExecutionError(
|
||||
"Invalid snapshot type '{0}'", format(snapshot_type))
|
||||
"Invalid snapshot type '{0}'".format(snapshot_type))
|
||||
except dbus.DBusException as exc:
|
||||
raise CommandExecutionError(
|
||||
'Error encountered while listing changed files: {0}'
|
||||
|
@ -305,17 +305,13 @@ class LazyLoaderSingleItem(TestCase):
|
||||
'''
|
||||
Checks that a KeyError is raised when the function key does not contain a '.'
|
||||
'''
|
||||
key = 'testing_no_dot'
|
||||
expected = "The key '{0}' should contain a '.'".format(key)
|
||||
with self.assertRaises(KeyError) as err:
|
||||
inspect.isfunction(self.loader['testing_no_dot'])
|
||||
|
||||
if six.PY2:
|
||||
self.assertEqual(err.exception[0],
|
||||
'The key \'%s\' should contain a \'.\'')
|
||||
else:
|
||||
self.assertEqual(
|
||||
six.text_type(err.exception),
|
||||
six.text_type(("The key '%s' should contain a '.'", 'testing_no_dot'))
|
||||
)
|
||||
result = err.exception.args[0]
|
||||
assert result == expected, result
|
||||
|
||||
|
||||
module_template = '''
|
||||
|
Loading…
Reference in New Issue
Block a user