From cd2187da65c1cd46d742168312ce3fdcd7e09936 Mon Sep 17 00:00:00 2001 From: Adam Sussman Date: Fri, 22 Jan 2021 01:19:57 -0800 Subject: [PATCH 1/3] add newlines to multiline error messages printed by StandardSink --- awslambdaric/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awslambdaric/bootstrap.py b/awslambdaric/bootstrap.py index be42814..7e08bb4 100644 --- a/awslambdaric/bootstrap.py +++ b/awslambdaric/bootstrap.py @@ -19,7 +19,7 @@ warnings.filterwarnings("ignore", category=DeprecationWarning) import imp -ERROR_LOG_LINE_TERMINATE = "\r" +ERROR_LOG_LINE_TERMINATE = "\r\n" ERROR_LOG_IDENT = "\u00a0" # NO-BREAK SPACE U+00A0 From 7fad7b328f56a8a71f90e7bb8cede5c22a26aaad Mon Sep 17 00:00:00 2001 From: Adam Sussman Date: Fri, 22 Jan 2021 01:26:40 -0800 Subject: [PATCH 2/3] test StandardSink stdout logging with newlines --- test/test_bootstrap.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/test_bootstrap.py b/test/test_bootstrap.py index 3d69038..427a5c1 100644 --- a/test/test_bootstrap.py +++ b/test/test_bootstrap.py @@ -404,11 +404,11 @@ def raise_exception_handler(json_input, lambda_context): ) # NOTE: Indentation characters are NO-BREAK SPACE (U+00A0) not SPACE (U+0020) - error_logs = "[ERROR] FaultExceptionType: Fault exception msg\r" - error_logs += "Traceback (most recent call last):\r" - error_logs += '  File "spam.py", line 3, in \r' - error_logs += "    spam.eggs()\r" - error_logs += '  File "eggs.py", line 42, in eggs\r' + error_logs = "[ERROR] FaultExceptionType: Fault exception msg\r\n" + error_logs += "Traceback (most recent call last):\r\n" + error_logs += '  File "spam.py", line 3, in \r\n' + error_logs += "    spam.eggs()\r\n" + error_logs += '  File "eggs.py", line 42, in eggs\r\n' error_logs += '    return "bacon"\n' self.assertEqual(mock_stdout.getvalue(), error_logs) @@ -523,11 +523,11 @@ def raise_exception_handler(json_input, lambda_context): bootstrap.StandardLogSink(), ) - error_logs = "[ERROR]\r" - error_logs += "Traceback (most recent call last):\r" - error_logs += '  File "spam.py", line 3, in \r' - error_logs += "    spam.eggs()\r" - error_logs += '  File "eggs.py", line 42, in eggs\r' + error_logs = "[ERROR]\r\n" + error_logs += "Traceback (most recent call last):\r\n" + error_logs += '  File "spam.py", line 3, in \r\n' + error_logs += "    spam.eggs()\r\n" + error_logs += '  File "eggs.py", line 42, in eggs\r\n' error_logs += '    return "bacon"\n' self.assertEqual(mock_stdout.getvalue(), error_logs) @@ -566,9 +566,9 @@ def test_handle_event_request_fault_exception_logging_syntax_error( sys.stderr.write(mock_stdout.getvalue()) - error_logs = "[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'a': unexpected EOF while parsing (, line 1)\r" - error_logs += "Traceback (most recent call last):\r" - error_logs += '  File "" Line 1\r' + error_logs = "[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'a': unexpected EOF while parsing (, line 1)\r\n" + error_logs += "Traceback (most recent call last):\r\n" + error_logs += '  File "" Line 1\r\n' error_logs += "    -\n" self.assertEqual(mock_stdout.getvalue(), error_logs) @@ -764,7 +764,7 @@ def test_application_json(self): ) def test_binary_request_binary_response(self): - event_body = b"\x89PNG\r\n\x1a\n\x00\x00\x00" + event_body = b"\x89PNG\r\n\n\x1a\n\x00\x00\x00" bootstrap.handle_event_request( lambda_runtime_client=self.lambda_runtime, request_handler=lambda event, ctx: event, @@ -783,7 +783,7 @@ def test_binary_request_binary_response(self): ) def test_json_request_binary_response(self): - binary_data = b"\x89PNG\r\n\x1a\n\x00\x00\x00" + binary_data = b"\x89PNG\r\n\n\x1a\n\x00\x00\x00" bootstrap.handle_event_request( lambda_runtime_client=self.lambda_runtime, request_handler=lambda event, ctx: binary_data, @@ -806,7 +806,7 @@ def test_binary_with_application_json(self): lambda_runtime_client=self.lambda_runtime, request_handler=lambda event, ctx: event, invoke_id="invoke-id", - event_body=b"\x89PNG\r\n\x1a\n\x00\x00\x00", + event_body=b"\x89PNG\r\n\n\x1a\n\x00\x00\x00", content_type="application/json", client_context_json=None, cognito_identity_json=None, @@ -865,7 +865,7 @@ def test_log_error_indentation_standard_log_sink(self, mock_stdout): ) bootstrap.log_error(err_to_log, bootstrap.StandardLogSink()) - expected_logged_error = "[ERROR] ErrorType: Error message\rTraceback (most recent call last):\r\xa0\xa0line1 \r\xa0\xa0line2 \r\xa0\xa0\n" + expected_logged_error = "[ERROR] ErrorType: Error message\r\nTraceback (most recent call last):\r\n\xa0\xa0line1 \r\n\xa0\xa0line2 \r\n\xa0\xa0\n" self.assertEqual(mock_stdout.getvalue(), expected_logged_error) def test_log_error_indentation_framed_log_sink(self): @@ -897,7 +897,7 @@ def test_log_error_empty_stacktrace_line_standard_log_sink(self, mock_stdout): ) bootstrap.log_error(err_to_log, bootstrap.StandardLogSink()) - expected_logged_error = "[ERROR] ErrorType: Error message\rTraceback (most recent call last):\rline1\r\rline2\n" + expected_logged_error = "[ERROR] ErrorType: Error message\r\nTraceback (most recent call last):\r\nline1\r\n\r\nline2\n" self.assertEqual(mock_stdout.getvalue(), expected_logged_error) def test_log_error_empty_stacktrace_line_framed_log_sink(self): From 97a15eb76a80bc6d5cb747f5cdef027bbb5b5e9c Mon Sep 17 00:00:00 2001 From: Adam Sussman Date: Fri, 22 Jan 2021 01:33:15 -0800 Subject: [PATCH 3/3] remove some unwanted binary test changes --- test/test_bootstrap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_bootstrap.py b/test/test_bootstrap.py index 427a5c1..9ef518c 100644 --- a/test/test_bootstrap.py +++ b/test/test_bootstrap.py @@ -764,7 +764,7 @@ def test_application_json(self): ) def test_binary_request_binary_response(self): - event_body = b"\x89PNG\r\n\n\x1a\n\x00\x00\x00" + event_body = b"\x89PNG\r\n\x1a\n\x00\x00\x00" bootstrap.handle_event_request( lambda_runtime_client=self.lambda_runtime, request_handler=lambda event, ctx: event, @@ -783,7 +783,7 @@ def test_binary_request_binary_response(self): ) def test_json_request_binary_response(self): - binary_data = b"\x89PNG\r\n\n\x1a\n\x00\x00\x00" + binary_data = b"\x89PNG\r\n\x1a\n\x00\x00\x00" bootstrap.handle_event_request( lambda_runtime_client=self.lambda_runtime, request_handler=lambda event, ctx: binary_data, @@ -806,7 +806,7 @@ def test_binary_with_application_json(self): lambda_runtime_client=self.lambda_runtime, request_handler=lambda event, ctx: event, invoke_id="invoke-id", - event_body=b"\x89PNG\r\n\n\x1a\n\x00\x00\x00", + event_body=b"\x89PNG\r\n\x1a\n\x00\x00\x00", content_type="application/json", client_context_json=None, cognito_identity_json=None,