diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2017-09-07 10:20:44 -0700 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2017-09-07 13:20:44 -0400 |
commit | e1e2d08508de0d163fe91071c6e576fc1812678d (patch) | |
tree | dc7814bf0b6e81f23bc43e2c6dd86776d3d1f0b7 /lib/ansible/plugins/cache | |
parent | 15fd23c6be2971996e602d9011181f07e4640608 (diff) | |
download | ansible-e1e2d08508de0d163fe91071c6e576fc1812678d.tar.gz |
Combine exception handling to simplify code (#29096)
Diffstat (limited to 'lib/ansible/plugins/cache')
-rw-r--r-- | lib/ansible/plugins/cache/__init__.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/ansible/plugins/cache/__init__.py b/lib/ansible/plugins/cache/__init__.py index 6537ffe223..27bb0d3064 100644 --- a/lib/ansible/plugins/cache/__init__.py +++ b/lib/ansible/plugins/cache/__init__.py @@ -112,15 +112,14 @@ class BaseFileCacheModule(BaseCacheModule): cachefile = "%s/%s" % (self._cache_dir, key) try: - try: - value = self._load(cachefile) - self._cache[key] = value - except ValueError as e: - 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))) - self.delete(key) - 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) + value = self._load(cachefile) + self._cache[key] = value + except ValueError as e: + 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))) + self.delete(key) + 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) 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))) raise KeyError |