mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Fixing bugs related to jfonfile cache plugin
* corrupt/invalid file causes tracebacks * incorrect initialization of display/_display in BaseCacheModule class * tweaking the way errors in get() on jsonfile caches work, to raise a proper AnsibleError in that situation so the playbook/task is stopped Fixes #12708
This commit is contained in:
12
lib/ansible/plugins/cache/jsonfile.py
vendored
12
lib/ansible/plugins/cache/jsonfile.py
vendored
@@ -68,9 +68,10 @@ class CacheModule(BaseCacheModule):
|
||||
value = json.load(f)
|
||||
self._cache[key] = value
|
||||
return value
|
||||
except ValueError:
|
||||
self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e)))
|
||||
raise KeyError
|
||||
except ValueError as e:
|
||||
self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, str(e)))
|
||||
self.delete(key)
|
||||
raise AnsibleError("The JSON cache file %s was corrupt, or did not otherwise contain valid JSON data. It has been removed, so you can re-run your command now.")
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
@@ -134,7 +135,10 @@ class CacheModule(BaseCacheModule):
|
||||
pass
|
||||
|
||||
def delete(self, key):
|
||||
del self._cache[key]
|
||||
try:
|
||||
del self._cache[key]
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
os.remove("%s/%s" % (self._cache_dir, key))
|
||||
except (OSError,IOError) as e:
|
||||
|
||||
Reference in New Issue
Block a user