Skip to content

Commit fa1e14f

Browse files
committed
Handle exceptions by using traceback.format_exc instead of extract_tb
1 parent b8a078c commit fa1e14f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lambda_local/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def execute(func, event, context):
124124
err = sys.exc_info()
125125
result = json.dumps({
126126
"errorMessage": str(err[1]),
127-
"stackTrace": traceback.extract_tb(err[2]),
127+
"stackTrace": traceback.format_exc(),
128128
"errorType": err[0].__name__
129129
}, indent=4, separators=(',', ': '))
130130
err_type = ERR_TYPE_EXCEPTION

tests/test_direct_invocations.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
python-lambda-local: Test Direct Inovactions
2+
python-lambda-local: Test Direct Invocations
33
(command-line and direct).
44
55
Meant for use with py.test.
@@ -13,6 +13,7 @@
1313
import os
1414
from lambda_local.main import run as lambda_run
1515
from lambda_local.main import call as lambda_call
16+
from lambda_local.main import ERR_TYPE_EXCEPTION
1617
from lambda_local.context import Context
1718

1819

@@ -21,6 +22,10 @@ def my_lambda_function(event, context):
2122
return 42
2223

2324

25+
def my_failing_lambda_function(event, context):
26+
raise Exception('Oh no')
27+
28+
2429
def test_function_call_for_pytest():
2530
(result, error_type) = lambda_call(
2631
my_lambda_function, {}, Context(1))
@@ -30,6 +35,13 @@ def test_function_call_for_pytest():
3035
assert result == 42
3136

3237

38+
def test_handle_exceptions_gracefully():
39+
(result, error_type) = lambda_call(
40+
my_failing_lambda_function, {}, Context(1))
41+
42+
assert error_type is ERR_TYPE_EXCEPTION
43+
44+
3345
def test_check_command_line():
3446
request = json.dumps({})
3547
request_file = 'check_command_line_event.json'

0 commit comments

Comments
 (0)