serverless-toolkit icon indicating copy to clipboard operation
serverless-toolkit copied to clipboard

fix(runtime-handler): fixes async handler functions throwing errors

Open philnash opened this issue 2 years ago • 1 comments

When a Twilio Function deemed an async function throws an error, the handler doesn't catch it and instead throws an unhandled promise rejection error.

Also, when constructing the context and the checks for valid account sids and auth tokens in the getTwilioClient function, we say that it should print the error. However, passing the logger to the context serializes and deserialises it, since it is being passed to another process, and and it is no longer an instance of Logger. This causes another error, trying to call on the logger's error function that no longer exists.

So, this PR does 2 things, it checks the handler function to see if it is an async function and calls it with await so that it can catch the error. And it sets shouldPrintMessage to true only if there is a logger object that has an error function. In the case of receiving an error from the forked process, this now logs the error with the original logger in the parent process.

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • [x] I acknowledge that all my contributions will be made under the project's license.

philnash avatar Apr 04 '22 09:04 philnash

⚠️ No Changeset found

Latest commit: 09612e774ebd56faf5b3e7c888f3a3324d1ea215

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Mar 26 '24 08:03 changeset-bot[bot]