awslabs / amazon-qldb-driver-nodejs

A NodeJs implementation of a driver for Amazon QLDB.
https://aws.amazon.com/qldb/?nc2=h_ql_prod_db_qldb
Apache License 2.0
53 stars 22 forks source link

Error handling inside executeLambda #579

Open Ahlaee opened 10 months ago

Ahlaee commented 10 months ago

Hello there,

I encountered an error handling issue when emitting custom errors inside executeLambda. The following pseudo code will create a TypeError:

try {
  await qldbDriver.executeLambda(async (txn) => {
    ...
    throw new CustomError ...
    ...
   });
} catch(error) {
  console.log(error);
}

-> TypeError: Right-hand side of 'instanceof' is not an object

If the error is thrown outside executeLambda it works the usual way:

try {
  throw new CustomError ...
  await qldbDriver.executeLambda(async (txn) => {
  ...
  });
} catch(error) {
  console.log(error);
}

-> e [Error]: CustomError ...

Is there something obvious I'm missing regarding emitting errors inside executeLambda? Should I consider error handling always outside of executeLambda? Would you need more context?

Thank you for your help!

Using:

tsc 5.2.2 "@aws-sdk/client-qldb": "^3.445.0", "amazon-qldb-driver-nodejs": "^3.0.1" "serverless": "^3.36.0", "serverless-bundle": "^6.0.0"

Running on AWS Lambda with node.js v18.x

prashantprabhakar commented 6 months ago

I have just tested the same stated versions but can not reproduce. You have any stack trace?

 "@aws-sdk/client-qldb": "3.445.0",
 "amazon-qldb-driver-nodejs": "3.0.1",

image