Non-Zero Exit Code is Swallowed
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description
When a Lambda throws an error, the SAM tool prints the exception, but a zero exit code is returned.
### Steps to reproduce
Create a Lambda that throws an Error.
Call the Lambda with SAM, e.g.: sam local invoke "lambda1"
### Observed result
```
{"errorMessage":"Test Error","errorType":"Error","stackTrace":["exports.handler (/var/task/index.js:24:9)"]}
✨ Done in 8.61s.
MLP-0U8HV2H:mediainfo user$ echo $?
0
```
### Expected result
An exit code of 1 or greater
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
```
1. MacOS
2. `sam --version`:
SAM CLI, version 0.14.0
`Add --debug flag to command you are running`
```
--debug
```
2019-03-25 18:11:08 Using SAM Template at /Users/user/projects/connect5-lambda-mediainfo/lambdas/mediainfo/template.yml
2019-03-25 18:11:08 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-03-25 18:11:08 Changing event name from before-call.apigateway to before-call.api-gateway
2019-03-25 18:11:08 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-03-25 18:11:08 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-03-25 18:11:08 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-03-25 18:11:08 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-03-25 18:11:08 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-03-25 18:11:08 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-03-25 18:11:08 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-03-25 18:11:08 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-03-25 18:11:08 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-03-25 18:11:08 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-03-25 18:11:08 Changing event name from before-call.apigateway to before-call.api-gateway
2019-03-25 18:11:08 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-03-25 18:11:08 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-03-25 18:11:08 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-03-25 18:11:08 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-03-25 18:11:08 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-03-25 18:11:08 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-03-25 18:11:08 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-03-25 18:11:08 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-03-25 18:11:08 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-03-25 18:11:08 local invoke command is called
2019-03-25 18:11:08 No Parameters detected in the template
2019-03-25 18:11:08 1 resources found in the template
2019-03-25 18:11:08 Found Serverless function with name='tfdefaultroutefile' and CodeUri='.'
2019-03-25 18:11:08 Trying paths: ['/Users/user/.docker/config.json', '/Users/user/.dockercfg']
2019-03-25 18:11:08 Found file at path: /Users/user/.docker/config.json
2019-03-25 18:11:08 Found 'auths' section
2019-03-25 18:11:08 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-03-25 18:11:08 http://localhost:None "GET /v1.35/_ping HTTP/1.1" 200 2
2019-03-25 18:11:08 Looking for credentials via: env
2019-03-25 18:11:08 Found credentials in environment variables.
2019-03-25 18:11:08 Loading JSON file: /usr/local/Cellar/aws-sam-cli/0.14.0/libexec/lib/python3.7/site-packages/botocore/data/endpoints.json
2019-03-25 18:11:08 Event choose-service-name: calling handler
2019-03-25 18:11:08 Loading JSON file: /usr/local/Cellar/aws-sam-cli/0.14.0/libexec/lib/python3.7/site-packages/botocore/data/lambda/2015-03-31/service-2.json
2019-03-25 18:11:08 Event creating-client-class.lambda: calling handler
2019-03-25 18:11:08 The s3 config key is not a dictionary type, ignoring its value of: None
2019-03-25 18:11:08 Setting lambda timeout as (60, 60)
2019-03-25 18:11:08 Loading JSON file: /usr/local/Cellar/aws-sam-cli/0.14.0/libexec/lib/python3.7/site-packages/botocore/data/_retry.json
2019-03-25 18:11:08 Registering retry handlers for service: lambda
2019-03-25 18:11:08 Trying paths: ['/Users/user/.docker/config.json', '/Users/user/.dockercfg']
2019-03-25 18:11:08 Found file at path: /Users/user/.docker/config.json
2019-03-25 18:11:08 Found 'auths' section
2019-03-25 18:11:08 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-03-25 18:11:08 Found one Lambda function with name 'tfdefaultroutefile'
2019-03-25 18:11:08 Invoking index.handler (nodejs8.10)
2019-03-25 18:11:08 No environment variables found for function 'tfdefaultroutefile'
2019-03-25 18:11:08 Environment variables overrides data is standard format
2019-03-25 18:11:08 Loading AWS credentials from session with profile 'default'
2019-03-25 18:11:08 Resolving code path. Cwd=/Users/user/projects/connect5-lambda-mediainfo/lambdas/mediainfo, CodeUri=.
2019-03-25 18:11:08 Resolved absolute path to code is /Users/user/projects/connect5-lambda-mediainfo/lambdas/mediainfo
2019-03-25 18:11:08 Code /Users/user/projects/connect5-lambda-mediainfo/lambdas/mediainfo is not a zip/jar file
2019-03-25 18:11:08 Skipping building an image since no layers were defined
2019-03-25 18:11:08 Trying paths: ['/Users/user/.docker/config.json', '/Users/user/.dockercfg']
2019-03-25 18:11:08 Found file at path: /Users/user/.docker/config.json
2019-03-25 18:11:08 Found 'auths' section
2019-03-25 18:11:08 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-03-25 18:11:08 http://localhost:None "GET /v1.35/images/lambci/lambda:nodejs8.10/json HTTP/1.1" 200 None
2019-03-25 18:11:08 Looking for auth config
2019-03-25 18:11:08 Looking for auth entry for 'docker.io'
2019-03-25 18:11:08 Found 'https://index.docker.io/v1/'
2019-03-25 18:11:08 No auth config found
2019-03-25 18:11:09 http://localhost:None "POST /v1.35/images/create?tag=nodejs8.10&fromImage=lambci%2Flambda HTTP/1.1" 200 None
Fetching lambci/lambda:nodejs8.10 Docker container image......
2019-03-25 18:11:09 Mounting /Users/user/projects/connect5-lambda-mediainfo/lambdas/mediainfo as /var/task:ro inside runtime container
2019-03-25 18:11:09 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2019-03-25 18:11:09 http://localhost:None "GET /v1.35/containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8/json HTTP/1.1" 200 None
2019-03-25 18:11:09 http://localhost:None "GET /v1.35/containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8/json HTTP/1.1" 200 None
2019-03-25 18:11:10 http://localhost:None "POST /v1.35/containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8/start HTTP/1.1" 204 0
2019-03-25 18:11:10 Starting a timer for 240 seconds for function 'tfdefaultroutefile'
2019-03-25 18:11:10 http://localhost:None "GET /v1.35/containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8/json HTTP/1.1" 200 None
2019-03-25 18:11:10 http://localhost:None "POST /containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0
START RequestId: a532a815-fc34-1203-07d4-70179e0debb5 Version: $LATEST
2019-03-26T01:11:11.221Z a532a815-fc34-1203-07d4-70179e0debb5 {"errorMessage":"Test Error","errorType":"Error","stackTrace":["exports.handler (/var/task/index.js:24:9)"]}
END RequestId: a532a815-fc34-1203-07d4-70179e0debb5
REPORT RequestId: a532a815-fc34-1203-07d4-70179e0debb5 Duration: 977.93 ms Billed Duration: 1000 ms Memory Size: 128 MMax Memory Used: 42 MB
2019-03-25 18:11:11 http://localhost:None "GET /v1.35/containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8/json HTTP/1.1" 200 None
2019-03-25 18:11:11 http://localhost:None "DELETE /v1.35/containers/774deb4e3a106fb54afd93528ff3c1490d998a5d547923bfe306c21e7685c5d8?v=False&link=False&force=True HTTP/1.1" 204 0
{"errorMessage":"Test Error","errorType":"Error","stackTrace":["exports.handler (/var/task/index.js:24:9)"]}
```
```
Contributor guide
Assessment
This issue has not been assessed yet.