Combine exception handling to simplify code (#29096)
This commit is contained in:
parent
15fd23c6be
commit
e1e2d08508
1 changed files with 8 additions and 9 deletions
17
lib/ansible/plugins/cache/__init__.py
vendored
17
lib/ansible/plugins/cache/__init__.py
vendored
|
@ -112,15 +112,14 @@ class BaseFileCacheModule(BaseCacheModule):
|
||||||
|
|
||||||
cachefile = "%s/%s" % (self._cache_dir, key)
|
cachefile = "%s/%s" % (self._cache_dir, key)
|
||||||
try:
|
try:
|
||||||
try:
|
value = self._load(cachefile)
|
||||||
value = self._load(cachefile)
|
self._cache[key] = value
|
||||||
self._cache[key] = value
|
except ValueError as e:
|
||||||
except ValueError as e:
|
display.warning("error in '%s' cache plugin while trying to read %s : %s. "
|
||||||
display.warning("error in '%s' cache plugin while trying to read %s : %s. "
|
"Most likely a corrupt file, so erasing and failing." % (self.plugin_name, cachefile, to_bytes(e)))
|
||||||
"Most likely a corrupt file, so erasing and failing." % (self.plugin_name, cachefile, to_bytes(e)))
|
self.delete(key)
|
||||||
self.delete(key)
|
raise AnsibleError("The cache file %s was corrupt, or did not otherwise contain valid data. "
|
||||||
raise AnsibleError("The cache file %s was corrupt, or did not otherwise contain valid data. "
|
"It has been removed, so you can re-run your command now." % cachefile)
|
||||||
"It has been removed, so you can re-run your command now." % cachefile)
|
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
display.warning("error in '%s' cache plugin while trying to read %s : %s" % (self.plugin_name, cachefile, to_bytes(e)))
|
display.warning("error in '%s' cache plugin while trying to read %s : %s" % (self.plugin_name, cachefile, to_bytes(e)))
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
|
Loading…
Reference in a new issue