Skip to content

split getFirst into two methods: getFirstOptional and getFirstRequired #3108

@tomholub

Description

@tomholub

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.getFirst to KeyStore.getFirstOptional and change return signature to Promise<KeyInfo | undefined>
  • add method KeyStore.getFirstRequired that contains just the call to KeyStore.getFirstOptional and Assert.abortAndRenderErrorIfKeyinfoEmpty(primaryKi);
  • in the whole codebase, replace getFirstOptional with getFirstRequired wherever 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 with Assert.abortAndRenderErrorIfKeyinfoEmpty(primaryKi);, this check can now be removed

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions