Skip to content

Commit

Permalink
feat: enhance error logging with args used
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Oct 3, 2024
1 parent 6cf2f6c commit e049b57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/integrations/google_workspace/google_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
non_critical_errors = {
"get_user": ["timed out"],
}
argument_string = ", ".join(
[str(arg) for arg in args] + [f"{k}={v}" for k, v in kwargs.items()]
)
argument_string = f"({argument_string})"

try:
result = func(*args, **kwargs)
Expand Down Expand Up @@ -121,7 +125,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
error in message for error in non_critical_errors[func_name]
):
logging.warning(
f"A non critical error occurred in function '{func.__module__}:{func.__name__}{*args, kwargs}': {e}"
f"A non critical error occurred in function '{func.__module__}:{func.__name__}{argument_string}': {e}"
)
else:
logging.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_handle_google_api_errors_catches_non_critical_error(mocked_logging_warn
assert result is None
mock_func.assert_called_once()
mocked_logging_warning.assert_called_once_with(
"A non critical error occurred in function 'mock_module:get_user('arg1', 'arg2', {'a': 'b'})': timed out"
"A non critical error occurred in function 'mock_module:get_user(arg1, arg2, a=b)': timed out"
)


Expand Down

0 comments on commit e049b57

Please sign in to comment.