in samcli/local/services/base_local_service.py [0:0]
def is_lambda_error_response(lambda_response):
"""
Check to see if the output from the container is in the form of an Error/Exception from the Lambda invoke
Parameters
----------
lambda_response str
The response the container returned
Returns
-------
bool
True if the output matches the Error/Exception Dictionary otherwise False
"""
is_lambda_user_error_response = False
lambda_response_error_dict_len = 2
lambda_response_error_with_stacktrace_dict_len = 3
try:
lambda_response_dict = json.loads(lambda_response)
# This is a best effort attempt to determine if the output (lambda_response) from the container was an
# Error/Exception that was raised/returned/thrown from the container. To ensure minimal false positives in
# this checking, we check for all the keys that can occur in Lambda raised/thrown/returned an
# Error/Exception. This still risks false positives when the data returned matches exactly a dictionary with
# the keys 'errorMessage', 'errorType', 'stackTrace' and 'cause'.
# This also accounts for a situation where there are three keys returned, two of which are
# 'errorMessage' and 'errorType', for languages with different error signatures
if (
isinstance(lambda_response_dict, dict)
and len(lambda_response_dict.keys() & {"errorMessage", "errorType"}) == lambda_response_error_dict_len
and (
(
len(lambda_response_dict.keys() & {"errorMessage", "errorType", "stackTrace", "cause"})
== len(lambda_response_dict)
)
or (len(lambda_response_dict) == lambda_response_error_with_stacktrace_dict_len)
)
):
is_lambda_user_error_response = True
except ValueError:
# If you can't serialize the output into a dict, then do nothing
pass
return is_lambda_user_error_response