cloud-sdk-js icon indicating copy to clipboard operation
cloud-sdk-js copied to clipboard

Catch Unresolved Promises

Open FrankEssenberger opened this issue 3 years ago • 1 comments

Our current implementation of the timeout is based on a race conditions. Here is a minimal example illsutrating the issue:

const timeoutSuccss = 1000
const timeoutFailure = 3000

async function promiseTest(){
    const success = new Promise((resolve, reject) =>
    setTimeout(
      () => resolve('Success!'),
      timeoutSuccss
    ));

    const failure = new Promise((resolve, reject) =>
    setTimeout(
      () => reject('Failure!'),
      timeoutFailure
    )
  );

  const result = await Promise.race([success,failure])
  console.log(result)
}

promiseTest()

The issue is that the faulure promise is kept open even if the race is lost and at a certain later time in Visual studio code your debugger stops at the uncaught exception if you enable the options:

image

One way to solve this would be to add a

failure.catch(()=>'catch it if success won the race.')

after the promise.race resolved successfully.

TODO

  • [ ] Investigate if there is a lib to wrap a promise in a timeout.
  • [ ] Implement a solution to catch to running timeout promise (search for the timeoutPromise which should be used or the Promise.race usage)

Acceptance Criteria

  • [ ] There are no uncaught exceptions if the timeout promise is irrelavant.

FrankEssenberger avatar Sep 15 '22 14:09 FrankEssenberger

Include this here: https://github.com/SAP/cloud-sdk-backlog/issues/667

FrankEssenberger avatar Dec 05 '22 17:12 FrankEssenberger

We will not work on this, due to the current priority.

jjtang1985 avatar Jul 04 '24 19:07 jjtang1985