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

Closed
JohanLi opened this issue May 10, 2024 · 1 comment · Fixed by #981
Closed
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
Member

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

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

Successfully merging a pull request may close this issue.

2 participants