Skip to content

Commit 5fdee65

Browse files
authored
Move unhandled exception warning message to init errors. (#189)
1 parent 224a920 commit 5fdee65

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

awslambdaric/bootstrap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ def handle_event_request(
201201
)
202202

203203
if error_result is not None:
204-
from .lambda_literals import lambda_unhandled_exception_warning_message
205204

206-
logging.warning(lambda_unhandled_exception_warning_message)
207205
log_error(error_result, log_sink)
208206
lambda_runtime_client.post_invocation_error(
209207
invoke_id, to_json(error_result), to_json(xray_fault)
@@ -509,6 +507,9 @@ def run(app_root, handler, lambda_runtime_api_addr):
509507
error_result = build_fault_result(sys.exc_info(), None)
510508

511509
if error_result is not None:
510+
from .lambda_literals import lambda_unhandled_exception_warning_message
511+
512+
logging.warning(lambda_unhandled_exception_warning_message)
512513
log_error(error_result, log_sink)
513514
lambda_runtime_client.post_init_error(error_result)
514515

tests/test_bootstrap.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,7 @@ def raise_exception_handler(json_input, lambda_context):
489489
)
490490

491491
# NOTE: Indentation characters are NO-BREAK SPACE (U+00A0) not SPACE (U+0020)
492-
error_logs = (
493-
lambda_unhandled_exception_warning_message
494-
+ "\n"
495-
+ "[ERROR] FaultExceptionType: Fault exception msg\r"
496-
)
492+
error_logs = "[ERROR] FaultExceptionType: Fault exception msg\r"
497493
error_logs += "Traceback (most recent call last):\r"
498494
error_logs += '  File "spam.py", line 3, in <module>\r'
499495
error_logs += "    spam.eggs()\r"
@@ -527,11 +523,7 @@ def raise_exception_handler(json_input, lambda_context):
527523
"tenant_id",
528524
bootstrap.StandardLogSink(),
529525
)
530-
error_logs = (
531-
lambda_unhandled_exception_warning_message
532-
+ "\n"
533-
+ "[ERROR] FaultExceptionType: Fault exception msg\rTraceback (most recent call last):\n"
534-
)
526+
error_logs = "[ERROR] FaultExceptionType: Fault exception msg\rTraceback (most recent call last):\n"
535527

536528
self.assertEqual(mock_stdout.getvalue(), error_logs)
537529

@@ -560,11 +552,7 @@ def raise_exception_handler(json_input, lambda_context):
560552
"tenant_id",
561553
bootstrap.StandardLogSink(),
562554
)
563-
error_logs = (
564-
lambda_unhandled_exception_warning_message
565-
+ "\n"
566-
+ "[ERROR] FaultExceptionType\rTraceback (most recent call last):\n"
567-
)
555+
error_logs = "[ERROR] FaultExceptionType\rTraceback (most recent call last):\n"
568556

569557
self.assertEqual(mock_stdout.getvalue(), error_logs)
570558

@@ -593,11 +581,7 @@ def raise_exception_handler(json_input, lambda_context):
593581
"tenant_id",
594582
bootstrap.StandardLogSink(),
595583
)
596-
error_logs = (
597-
lambda_unhandled_exception_warning_message
598-
+ "\n"
599-
+ "[ERROR] Fault exception msg\rTraceback (most recent call last):\n"
600-
)
584+
error_logs = "[ERROR] Fault exception msg\rTraceback (most recent call last):\n"
601585

602586
self.assertEqual(mock_stdout.getvalue(), error_logs)
603587

@@ -635,7 +619,7 @@ def raise_exception_handler(json_input, lambda_context):
635619
"tenant_id",
636620
bootstrap.StandardLogSink(),
637621
)
638-
error_logs = lambda_unhandled_exception_warning_message + "\n[ERROR]\r"
622+
error_logs = "[ERROR]\r"
639623
error_logs += "Traceback (most recent call last):\r"
640624
error_logs += '  File "spam.py", line 3, in <module>\r'
641625
error_logs += "    spam.eggs()\r"
@@ -671,21 +655,11 @@ def raise_exception_handler(json_input, lambda_context):
671655
)
672656

673657
stdout_value = mock_stdout.getvalue()
674-
received_warning = stdout_value.split("\n")[0]
675-
received_rest = stdout_value[len(received_warning) + 1 :]
676-
677-
warning = json.loads(received_warning)
678-
self.assertEqual(warning["level"], "WARNING")
679-
self.assertEqual(warning["message"], lambda_unhandled_exception_warning_message)
680-
self.assertEqual(warning["logger"], "root")
681-
self.assertIn("timestamp", warning)
682658

683659
# this line is not in json because of the way the test runtime is bootstrapped
684-
error_logs = (
685-
"\n[ERROR] FaultExceptionType\rTraceback (most recent call last):\n"
686-
)
660+
error_logs = "[ERROR] FaultExceptionType\rTraceback (most recent call last):\n"
687661

688-
self.assertEqual(received_rest, error_logs)
662+
self.assertEqual(stdout_value, error_logs)
689663

690664

691665
class TestXrayFault(unittest.TestCase):

0 commit comments

Comments
 (0)