Skip to content

Commit 462d685

Browse files
Pushkar Chawdaedhzsz
Pushkar Chawda
authored andcommitted
errorMessage missing from exception response, when errorMessage field is empty or None
1 parent 21e67e5 commit 462d685

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

awslambdaric/bootstrap.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,9 @@ def result(*args):
9090

9191

9292
def make_error(error_message, error_type, stack_trace):
93-
result = {}
94-
if error_message:
95-
result["errorMessage"] = error_message
96-
if error_type:
97-
result["errorType"] = error_type
98-
if stack_trace:
99-
result["stackTrace"] = stack_trace
93+
result = {'errorMessage': error_message if error_message else "",
94+
'errorType': error_type if error_type else "",
95+
'stackTrace': stack_trace if stack_trace else []}
10096
return result
10197

10298

test/test_bootstrap.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def raise_exception_handler(json_input, lambda_context):
435435
0,
436436
bootstrap.StandardLogSink(),
437437
)
438-
error_logs = "[ERROR] FaultExceptionType: Fault exception msg\n"
438+
error_logs = "[ERROR] FaultExceptionType: Fault exception msg\rTraceback (most recent call last):\n"
439439

440440
self.assertEqual(mock_stdout.getvalue(), error_logs)
441441

@@ -461,7 +461,7 @@ def raise_exception_handler(json_input, lambda_context):
461461
0,
462462
bootstrap.StandardLogSink(),
463463
)
464-
error_logs = "[ERROR] FaultExceptionType\n"
464+
error_logs = "[ERROR] FaultExceptionType\rTraceback (most recent call last):\n"
465465

466466
self.assertEqual(mock_stdout.getvalue(), error_logs)
467467

@@ -487,7 +487,7 @@ def raise_exception_handler(json_input, lambda_context):
487487
0,
488488
bootstrap.StandardLogSink(),
489489
)
490-
error_logs = "[ERROR] Fault exception msg\n"
490+
error_logs = "[ERROR] Fault exception msg\rTraceback (most recent call last):\n"
491491

492492
self.assertEqual(mock_stdout.getvalue(), error_logs)
493493

@@ -835,7 +835,7 @@ def test_log_error_standard_log_sink(self, mock_stdout):
835835
err_to_log = bootstrap.make_error("Error message", "ErrorType", None)
836836
bootstrap.log_error(err_to_log, bootstrap.StandardLogSink())
837837

838-
expected_logged_error = "[ERROR] ErrorType: Error message\n"
838+
expected_logged_error = "[ERROR] ErrorType: Error message\rTraceback (most recent call last):\n"
839839
self.assertEqual(mock_stdout.getvalue(), expected_logged_error)
840840

841841
def test_log_error_framed_log_sink(self):
@@ -844,14 +844,17 @@ def test_log_error_framed_log_sink(self):
844844
err_to_log = bootstrap.make_error("Error message", "ErrorType", None)
845845
bootstrap.log_error(err_to_log, log_sink)
846846

847-
expected_logged_error = "[ERROR] ErrorType: Error message"
847+
expected_logged_error = "[ERROR] ErrorType: Error message\nTraceback (most recent call last):"
848848

849849
with open(temp_file.name, "rb") as f:
850850
content = f.read()
851851

852852
frame_type = int.from_bytes(content[:4], "big")
853853
self.assertEqual(frame_type, 0xA55A0001)
854854

855+
actual_message = content[8:].decode()
856+
self.assertEqual(actual_message, expected_logged_error)
857+
855858
length = int.from_bytes(content[4:8], "big")
856859
self.assertEqual(length, len(expected_logged_error.encode("utf8")))
857860

0 commit comments

Comments
 (0)