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

Throw DOMExceptions, not Errors (maybe?) #48

Closed
Quelklef opened this issue Jun 21, 2020 · 3 comments
Closed

Throw DOMExceptions, not Errors (maybe?) #48

Quelklef opened this issue Jun 21, 2020 · 3 comments

Comments

@Quelklef
Copy link

Quelklef commented Jun 21, 2020

fake-indexeddb currently throws exceptions that are Error objects, but IndexedDB throws DOMExceptions.

Of course, this is a little sticky 'cause fake-indexeddb is on Node, but there seems to be a well-known DOMException polyfill that could be used.

Seems like an easy change: just modify src/lib/errors.ts, right?. I can try to make a PR with your go-ahead.

@dumbmatter
Copy link
Owner

Thanks for the suggestion!

But I don't know if it's worth it... what would be gained, the Error.code property? That's already deprecated and I'm not sure if anyone uses it for IndexedDB. Anything else?

If there's a compelling use case, then yes please go for it. And also in src/test/web-platform-tests/wpt-env.js replace global.DOMException = Error; with importing that module to the global scope.

@Quelklef
Copy link
Author

Quelklef commented Jun 21, 2020

My current use-case is code that looks like the following:

try {
  await doDbOperation();
} catch (err) {
  if (err instanceof DOMException && err.name === 'NotFoundError') {
    throw new MyErrorWrapper('message');
  } else {
    throw err;
  }
}

Cool, I'll see what I can do.

@dumbmatter
Copy link
Owner

Yeah that makes sense, I'd accept a PR :)

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

2 participants