-
Notifications
You must be signed in to change notification settings - Fork 52
Closed
Description
Almost all calls of KeyStore.getFirst assume that there will be a key returned. Many times, but not always, we also test it right below:
const primaryKi = await KeyStore.getFirst(this.acctEmail);
Assert.abortAndRenderErrorIfKeyinfoEmpty(primaryKi);This is error prone, many times we forget to check.
But in some situations, we actually expect that that the key may not be present. You can tell such situations in case it follows with if(primaryKi) { ... } or something similar.
Todo in this issue:
- rename
KeyStore.getFirsttoKeyStore.getFirstOptionaland change return signature toPromise<KeyInfo | undefined> - add method
KeyStore.getFirstRequiredthat contains just the call toKeyStore.getFirstOptionalandAssert.abortAndRenderErrorIfKeyinfoEmpty(primaryKi); - in the whole codebase, replace
getFirstOptionalwithgetFirstRequiredwherever it seems to make sense - that is practically the whole codebase except maybe setup screen and other places, if any, that actually don't expect key to be present. - where you switched the call to
getFirstRequired, if that line followed withAssert.abortAndRenderErrorIfKeyinfoEmpty(primaryKi);, this check can now be removed