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

Exceptions occurring inside SimpleCache's getOrSet cannot be caught from the outside #777

Open
JohanLi opened this issue May 10, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@JohanLi
Copy link

JohanLi commented May 10, 2024

Hello!

Stumbled upon a gotcha recently, where this does not behave as expected:

try {
  await SimpleCache.getOrSet('key', async () => {
    throw Error()

    return {
      value: 'value',
      ttl: 60
    }
  });
} catch (e) {
  // the exception inside the set callback will not be caught here
}

I understand that there's a lot going on under the hood with SimpleCache (request collapsing and all), but it'd be more convenient if you could catch exceptions from the "outside". At the very least, this behavior should be documented.

@guybedford
Copy link
Contributor

I agree it would make sense to treat failures on the setter promise as failures of the operation. Thanks for bringing this up.

@guybedford guybedford added the enhancement New feature or request label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants