Provider: AWS
Runtime: NodeJS 12.x
I’m using Typescript, so using the serverless-plugin-typescript
plugin.
I have Serverless Dashboard setup for monitoring.
Before using Serverless to deploy my functions, when an error was thrown by my handler functions, the error would result in an Invocation error and would appear in CloudWatch logs as :
ERROR Invoke Error { … my custom error … }
Now, when an error is thrown, the final logs of the failing request in Lambda looks like :
ERROR Invoke Error
{
“errorType”: “TypeError”,
“errorMessage”: “The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of InternalServerErrorException”,
“code”: “ERR_INVALID_ARG_TYPE”,
“stack”: [
“TypeError [ERR_INVALID_ARG_TYPE] [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of InternalServerErrorException”,
" at Function.from (buffer.js:327:9)",
" at e.exports.error (/var/task/serverless_sdk/index.js:9:140585)",
" at _ (/var/task/serverless_sdk/index.js:9:135767)",
" at /var/task/serverless_sdk/index.js:9:137263",
" at new Promise ()",
" at /var/task/serverless_sdk/index.js:9:137248",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
InternalServerErrorException being the class of the custom error object that I want to throw (actually it’s from the NestJS framework but anyway).
I looks like the serverless sdk is trying to catch this error and do something with it before throwing it again, but some sort of serialization fails and thus the Invocation error is related to this error instead of my actual error.
It turns out to be pretty difficult to have info about what is happening under the hood with Serverless SDK and what it is trying to do.
Can someone explain this to me please ?