diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5325016..9c747d2 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -47,3 +47,8 @@ Version 0.1.9 ------------- - Support latest boto3. + +Version 0.1.10 +-------------- + + - Fix traceback output when exception happens. diff --git a/LICENSE b/LICENSE index c4d8dfd..282b0e8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2018 HDE, Inc. +Copyright (c) 2015-2019 HENNGE K.K. (formerly known as HDE, Inc.) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lambda_local/main.py b/lambda_local/main.py index f3ff166..1f5f83f 100644 --- a/lambda_local/main.py +++ b/lambda_local/main.py @@ -124,7 +124,7 @@ def execute(func, event, context): err = sys.exc_info() result = json.dumps({ "errorMessage": str(err[1]), - "stackTrace": traceback.extract_tb(err[2]), + "stackTrace": traceback.format_tb(err[2]), "errorType": err[0].__name__ }, indent=4, separators=(',', ': ')) err_type = ERR_TYPE_EXCEPTION diff --git a/setup.py b/setup.py index de50429..8ba4ac3 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def run_tests(self): sys.exit(pytest.main(self.test_args)) -version = "0.1.9" +version = "0.1.10" TEST_REQUIRE = ['pytest'] if sys.version_info[0] == 2: diff --git a/tests/test_direct_invocations.py b/tests/test_direct_invocations.py index c496a4d..b49eaf7 100644 --- a/tests/test_direct_invocations.py +++ b/tests/test_direct_invocations.py @@ -1,5 +1,5 @@ ''' -python-lambda-local: Test Direct Inovactions +python-lambda-local: Test Direct Invocations (command-line and direct). Meant for use with py.test. @@ -13,6 +13,7 @@ import os from lambda_local.main import run as lambda_run from lambda_local.main import call as lambda_call +from lambda_local.main import ERR_TYPE_EXCEPTION from lambda_local.context import Context @@ -21,6 +22,10 @@ def my_lambda_function(event, context): return 42 +def my_failing_lambda_function(event, context): + raise Exception('Oh no') + + def test_function_call_for_pytest(): (result, error_type) = lambda_call( my_lambda_function, {}, Context(1)) @@ -30,6 +35,13 @@ def test_function_call_for_pytest(): assert result == 42 +def test_handle_exceptions_gracefully(): + (result, error_type) = lambda_call( + my_failing_lambda_function, {}, Context(1)) + + assert error_type is ERR_TYPE_EXCEPTION + + def test_check_command_line(): request = json.dumps({}) request_file = 'check_command_line_event.json' @@ -51,3 +63,26 @@ def test_check_command_line(): os.remove(request_file) assert p.exitcode == 0 + + +def test_check_command_line_error(): + request = json.dumps({}) + request_file = 'check_command_line_event.json' + with open(request_file, "w") as f: + f.write(request) + + args = argparse.Namespace(event=request_file, + file='tests/test_direct_invocations.py', + function='my_failing_lambda_function', + timeout=1, + environment_variables='', + library=None, + version_name='', + arn_string='' + ) + p = Process(target=lambda_run, args=(args,)) + p.start() + p.join() + + os.remove(request_file) + assert p.exitcode == 1