dherault / dherault/serverless-offline
Python lambda times out when an unhandled error occurs, instead of terminating and forwarding the error to FunctionError.
- Dominant language
- JavaScript
- Stars
- 5.3k
- Forks
- 811
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
## Bug Report
The python lambda times out if an unhandled error occurs (for example a runtime exception), the expected behaviour is to terminate the funtion and when the lambda is invoked to populate the `FunctionError` of the response with the error. However no information about the unhandled error is shown and the lambda continues to execute until a timeout. After some digging the problems seems to come from the `invoke.py` file in `src/lambda/handler-runner/python-runner`. Another thing to consider is that if an error occur during the imports (before the handler lambda is invoked) this also results in a time out, but should yield an error send again to the `FunctionError`.
**Current Behavior**
The python lambda times out if an unhandled error occurs instead of terminating.
**Sample Code**
```
from aws_lambda_typing import context, events
raise Exception("Random exception occurs")
def handler(event: events.EventBridgeEvent, _ctx: context.Context):
...
```
- file: serverless.yml
```yaml
service: my-service
plugins:
- serverless-python-requirements
- serverless-plugin-ifelse
- serverless-prune-plugin
- serverless-offline
provider:
runtime: python3.11
stage: dev
functions:
factors:
handler: src.handlers.factors.handler
timeout: 29
```
**Expected behavior/code**
After encountering unhandled exception the lambda should be terminated and immediate response should be returned with the error encountered.
**Environment**
- `serverless` version: v3.39.0
- `serverless-offline` version: v14.0.0
- `python` version: v3.11
- `OS`: macOS 14.6.1
**Possible Solution**
Use a try-except block to handle the error that is thrown and return the information using the `sys.stdout.write()` with argument which contains `__offline_payload__` with information about the error as JSON and `status_code` set to 500 for example.
**Additional context/Screenshots**
Contributor guide
Assessment
This issue has not been assessed yet.