fastly / js-compute-runtime

JavaScript SDK and runtime for building Fastly Compute applications
https://developer.fastly.com/learning/compute/javascript/
Apache License 2.0
193 stars 26 forks source link

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

Open JohanLi opened 1 month ago

JohanLi commented 1 month ago

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 commented 1 month ago

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