Crypho / cordova-plugin-secure-storage

Secure storage plugin for Apache Cordova
MIT License
278 stars 269 forks source link

`get()` throwing "errSecItemNotFound" #51

Closed szh closed 8 years ago

szh commented 8 years ago

When an item isn't present in the iOS keychain, usually get() returns null, but sometimes it throws "errSecItemNotFound".

ggozad commented 8 years ago

Would appreciate some more feedback on this, perhaps a PR?

ggozad commented 8 years ago

I released a new version and added some more tests to cover this. It works fine here, the error callback should always be called, please test and let me know if it still fails for you.

szh commented 8 years ago

Thanks for the quick response. I went ahead and ran the tests, and they do pass. Unfortunately it's very hard to reproduce this error. It usually happens when I launch the app, in case that helps. I actually have code in my error handler to try to catch the error but it seems to either skip it or maybe it throws the error even after the handler is called:

this.ss.get((val) => resolve(val), (e) => {
  if (String(e).includes("errSecItemNotFound")) {
    resolve(null); // Item not found in Keychain
  } else {
    reject(e);
  }
}, key);
ggozad commented 8 years ago

I am guessing you do wait for deviceready before everything?

With regards to the snippet: SecureStorage.get will reject if it does not find a value. You can of course catch that and return null instead, but does it ever return null when there is no such item?

szh commented 8 years ago

Yes, I'm waiting for deviceready. You're right, it doesn't return null. I thought it was, b/c I was handling that in code elsewhere in my app. I guess there's really no way to fix this if we can't reproduce it. I'll report back if I have more details that could help.