Skip to content
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

update traceback.format_exception etype argument #2663

Merged
merged 3 commits into from
Sep 10, 2022
Merged
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 azurelinuxagent/common/utils/textutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def format_exception(exception):
if tb is None or (sys.version_info[0] == 2 and e != exception):
msg += "[Traceback not available]"
else:
msg += ''.join(traceback.format_exception(etype=type(exception), value=exception, tb=tb))
msg += ''.join(traceback.format_exception(type(exception), value=exception, tb=tb))

return msg

20 changes: 20 additions & 0 deletions tests/utils/test_text_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ def test_format_memory_value(self):
self.assertRaises(ValueError, textutil.format_memory_value, 'KiloBytes', 1)
self.assertRaises(TypeError, textutil.format_memory_value, 'bytes', None)

def test_format_exception(self):
"""
Test formatting of exception into human-readable format
"""

def raise_exception(count=3):
if count <= 1:
raise Exception("Test Exception")
raise_exception(count - 1)

msg = ""
try:
raise_exception()
except Exception as e:
msg = textutil.format_exception(e)

self.assertIn("Test Exception", msg)
# Raise exception at count 1 after two nested calls since count starts at 3
self.assertEqual(2, msg.count("raise_exception(count - 1)"))


if __name__ == '__main__':
unittest.main()