dherault / dherault/serverless-offline
Cryptic error message when returning non-serializable data
- Dominant language
- JavaScript
- Stars
- 5.3k
- Forks
- 811
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
## Bug Report
**Current Behavior**
When you return non-serializible data from the lambda, serverless prints very cryptic error message with no user code stack trace and 0 information
Example code:
```ts
export const handler = async () => ({
ok: "serializable",
noOk: () => {}, // this line breaks the whole lambda
});
```
Error when caaling this endpoint:
```bash
GET /dev/example-fn (λ: example-fn)
✖ Uncaught exception
Environment: darwin, node 16.19.0, framework 3.24.1 (local), plugin 6.2.2, SDK 4.3.2
Credentials: Local, "default" profile
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({})
at __node_internal_captureLargerStackTrace (node:internal/errors:478:5)
at new NodeError (node:internal/errors:387:5)
at Worker.emit (node:events:502:17)
at Worker.emit (node:domain:489:12)
at Worker.[kOnErrorMessage] (node:internal/worker:298:10)
at Worker.[kOnMessage] (node:internal/worker:309:37)
at MessagePort. (node:internal/worker:205:57)
at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:736:20)
at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
```
I traced it down to this TODO line of code in serverless-offline
https://github.com/dherault/serverless-offline/blob/5b198a752c8cfdcbde5e3eb7e041a64ac3626289/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js#L29-L30
**Expected behavior/code**
Probably one of the two would be good
- strip out non-serializable data and show warning about passing non-serializable data
- throw error about passing non-serializable data
**Misc**
I was not that familiar with Serverless (using it for a few weeks only) so I have spent a lot of time figuring this one out (probably around 10 hours) - I had no idea where to look for what was wrong, and I had to connect to debugger and step through serverless-offline code to figure this out. So having good error message in this place could probably be big usability/accessibility win for future versions.
Contributor guide
Assessment
This issue has not been assessed yet.