Skip to content

Fixing format_traceback's change of signature #1123

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

Merged
merged 2 commits into from
Oct 18, 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
13 changes: 10 additions & 3 deletions azure_functions_worker/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
error_handler: Optional[logging.Handler] = None


def format_exception(exception):
def format_exception(exception: Exception) -> str:
msg = str(exception) + "\n"
msg += ''.join(traceback.format_exception(
etype=type(exception), value=exception, tb=exception.__traceback__))
if sys.version_info.minor < 10:
msg += ''.join(traceback.format_exception(
etype=type(exception),
tb=exception.__traceback__,
value=exception))
elif sys.version_info.minor == 10:
msg += ''.join(traceback.format_exception(exception))
else:
msg = str(exception)
return msg


Expand Down
4 changes: 2 additions & 2 deletions azure_functions_worker/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def is_true_like(setting: str) -> bool:
if setting is None:
return False

return setting.lower().strip() in ['1', 'true', 't', 'yes', 'y']
return setting.lower().strip() in {'1', 'true', 't', 'yes', 'y'}


def is_false_like(setting: str) -> bool:
if setting is None:
return False

return setting.lower().strip() in ['0', 'false', 'f', 'no', 'n']
return setting.lower().strip() in {'0', 'false', 'f', 'no', 'n'}


def is_envvar_true(env_key: str) -> bool:
Expand Down
25 changes: 25 additions & 0 deletions tests/unittests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest

from azure_functions_worker import logging as flog
from azure_functions_worker.logging import format_exception


class TestLogging(unittest.TestCase):
Expand Down Expand Up @@ -33,3 +34,27 @@ def test_customer_log_namespace(self):
self.assertFalse(flog.is_system_log_category('protobuf'))
self.assertFalse(flog.is_system_log_category('root'))
self.assertFalse(flog.is_system_log_category(''))

def test_format_exception(self):
def call0(fn):
call1(fn)

def call1(fn):
call2(fn)

def call2(fn):
fn()

def raising_function():
raise ValueError("Value error being raised.", )

try:
call0(raising_function)
except ValueError as e:
processed_exception = format_exception(e)
self.assertIn("call0", processed_exception)
self.assertIn("call1", processed_exception)
self.assertIn("call2", processed_exception)
self.assertIn("f", processed_exception)
self.assertIn("tests/unittests/test_logging.py",
processed_exception)