Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions azure_functions_worker/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@

def format_exception(exception):
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:
return 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)