solana-playground icon indicating copy to clipboard operation
solana-playground copied to clipboard

Non-awaited async function errors don't get caught

Open acheroncrypto opened this issue 1 year ago • 2 comments

Problem

The following client code gets caught:

function throwError() {
  throw new Error("Failure!");
}

throwError();
async function throwError() {
  throw new Error("Failure!");
}

await throwError();

and prints to terminal correctly:

$ run
Running client...
  client.ts:
    Uncaught error: Failure!

but the error doesn't get caught if it's an async function without an await call:

async function throwError() {
  throw new Error("Failure!");
}

throwError();

Solution

Catch the error from the iframe and print it in the terminal similar to how the other errors are handled.

acheroncrypto avatar Dec 30 '23 04:12 acheroncrypto