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

FIX: ExceptionFormatter infinite recursion traceback #1066

Closed
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions loguru/_better_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def tokenize(source):
return


class ExceptionFormatterRecursionError(Exception):
pass


class ExceptionFormatter:
_default_theme = {
"introduction": "\x1b[33m\x1b[1m{}\x1b[0m",
Expand Down
12 changes: 9 additions & 3 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
from threading import current_thread

from . import _asyncio_loop, _colorama, _defaults, _filters
from ._better_exceptions import ExceptionFormatter
from ._better_exceptions import ExceptionFormatter, ExceptionFormatterRecursionError
from ._colorizer import Colorizer
from ._contextvars import ContextVar
from ._datetime import aware_now
Expand Down Expand Up @@ -1219,6 +1219,7 @@ def catch(
class Catcher:
def __init__(self, from_decorator):
self._from_decorator = from_decorator
self._already_logging_exception = False

def __enter__(self):
return None
Expand All @@ -1239,8 +1240,13 @@ def __exit__(self, type_, value, traceback_):
if from_decorator:
depth += 1

catch_options = [(type_, value, traceback_), depth, True] + options
logger._log(level, from_decorator, catch_options, message, (), {})
if not self._already_logging_exception:
self._already_logging_exception = True
catch_options = [(type_, value, traceback_), depth, True] + options
logger._log(level, from_decorator, catch_options, message, (), {})
self._already_logging_exception = False
else:
raise ExceptionFormatterRecursionError()

if onerror is not None:
onerror(value)
Expand Down
Loading