Skip to content

Correctly format stdout (StandardSink) multi-line errors #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion awslambdaric/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
30 changes: 15 additions & 15 deletions test/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <module>\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 <module>\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)
Expand Down Expand Up @@ -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 <module>\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 <module>\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)
Expand Down Expand Up @@ -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 (<string>, line 1)\r"
error_logs += "Traceback (most recent call last):\r"
error_logs += '  File "<string>" Line 1\r'
error_logs = "[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'a': unexpected EOF while parsing (<string>, line 1)\r\n"
error_logs += "Traceback (most recent call last):\r\n"
error_logs += '  File "<string>" Line 1\r\n'
error_logs += "    -\n"

self.assertEqual(mock_stdout.getvalue(), error_logs)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down