Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error returned during a callback on localForage.getItem #14

Closed
operatorjen opened this issue Dec 2, 2013 · 3 comments
Closed

No error returned during a callback on localForage.getItem #14

operatorjen opened this issue Dec 2, 2013 · 3 comments

Comments

@operatorjen
Copy link

I noticed that localForage.getItem only returns a value if it is successful but never if there is an error. Generally I would expect the following behaviour:

localForage.getItem(itemKey, function (err, value) {
  if (err) {
    console.error('error: ', err);
  } else {
    console.log('value: ', value);
  }
});

Although localStorage doesn't return callbacks, it seems like the indexedDB part should at least return something if it were to go wrong so that users can handle the result accordingly.

@sole
Copy link
Contributor

sole commented Dec 3, 2013

I think I guess right when I presume that the reason there are no errors returned is because localForage is modeled after localStorage which likewise doesn't have a way to return 'errors':
https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

According to the spec at http://www.w3.org/TR/webstorage/#storage-0 if we read a key that doesn't exist, we should get a null value. If writing fails, the most it can happen is a QuotaExceededError exception is thrown (!!!).

Not sure how to proceed about exceptions with an async interface. I guess it's saner to switch to the err, value function signature proposed by @ednapiranha , but then we won't be that close to localStorage. Opinions? :-)

@tofumatt
Copy link
Member

tofumatt commented Dec 3, 2013

We can certainly add failure callbacks (and promise rejections, when they make it into master), but I don't expect reading unset keys to fail, I personally do expect them to just return null (I could be convinced of returning undefined as well, except then it's more work to have that carry over to the localStorage driver; we'd essentially have to test for the existence of a key rather than the return value from calling said key).

Like @sole says too: there aren't really errors that should bubble up unless there's something wrong with the storage engine itself; getting and setting data, aside from hitting the quota, shouldn't ever cause errors.

@tofumatt
Copy link
Member

I think this should be covered by #60, so I'll close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants