Recover safely if the add-on store cache is invalid#16461
Conversation
| return None | ||
| try: | ||
| data = cacheData["data"] | ||
| cachedAddonData = _createStoreCollectionFromJson(data) |
There was a problem hiding this comment.
I'd like to see better exception handling in _createStoreCollectionFromJson. In particular, if we get a JSONEncodeError or KeyError due to malformed data, invalidate the cache.
There was a problem hiding this comment.
Isn't that already occurring here for KeyError? Also I think you mean JSONDecodeError
There was a problem hiding this comment.
except (KeyError, JSONDecodeError):
There was a problem hiding this comment.
please change the exception handling below on line 189 to include JSONDecodeError
There was a problem hiding this comment.
@seanbudd , I've included JSONDecodeError in the exception as you requested.
There was a problem hiding this comment.
have you tested this? It doesnt seem like JSONDecodeError is imported from anywhere
There was a problem hiding this comment.
No, sorry, I haven't tested it and in fact VS Code is raising a warning. I cannot test this now. I'll try to import JSONDecodeError
There was a problem hiding this comment.
@seanbudd , I've imported JSONDecodeError and VS Code doesn't show warnings.
There was a problem hiding this comment.
please let me know when you have tested the code - we do not review or merge untested code
|
I've used the suggestion provided by @gerald-hartig for handling exceptions. I think this is ready for review. |
See test results for failed build of commit 311ee62e77 |
| with open(cacheFilePath, 'r', encoding='utf-8') as cacheFile: | ||
| cacheData = json.load(cacheFile) | ||
| except Exception: | ||
| except (KeyError, JSONDecodeError): |
There was a problem hiding this comment.
No, I think the bare except was okay here (back out this change). I was referring to guarding the json.loads call in _createStoreCollectionFromJson itself with a try/except, or ensure appropriate exception handling at all callsites.
There was a problem hiding this comment.
I don't think that's necessary, an error being raised outside of loading the cached data from file on startup will fail safely.
I'll revert my last commit. For any reason unit tests are failing now. About the better handling of exception in _createStoreCollectionFromJson, I'm not sure if should be done here or in a different PR. |
See test results for failed build of commit 71c3f870d5 |
|
System tests are failing, I don't now why. |
|
@nvdaes - don't need to worry about unexpected failures
|
|
@seanbudd, I've tested this now, trying to change the file encoding (without gettting actually errors), and removing an addonId. |
| if NVDAState.shouldWriteToDisk(): | ||
| os.remove(cacheFilePath) | ||
| return None | ||
| from json import JSONDecodeError |
There was a problem hiding this comment.
please import this from the base file, there is no need for this to be a lazy import
|
@nvdaes - can you resolve merge conflicts here please? |
|
Note that this is targeting beta - so please merge in origin/beta and move the change log entry to changes.md |
|
It appears |
|
@seanbudd , I have fixed conflicts and moved changelog entry to readme. Also, I run git submodule update and miscDeps are updated. |
|
@nvdaes - this Pr is now only the miscdeps changes |
Link to issue number:
Fixes #16362
Summary of the issue:
When cache files of the add-on store contain invalid data, NVDA is restarted.
Description of user facing changes
None
Description of development approach
In the
_getCachedAddonDatafunction of the_DataManagerclass, acachedAddonDatavariable will try to get the value of the _createStoreCollectionFromJson(data)`.So, if data doesn't match that model, the same exception of other invalid required values will be raised, and NVDA won't be restarted.
Testing strategy:
Known issues with pull request:
None
Code Review Checklist: