loguru icon indicating copy to clipboard operation
loguru copied to clipboard

TypeError: __init__() missing 1 required positional argument: 'reason'

Open TommeyChang opened this issue 5 years ago • 1 comments

Traceback (most recent call last): File "/home/stamp/.local/share/virtualenvs/backend-qOgQL7Z8/lib/python3.7/site-packages/loguru/_handler.py", line 270, in _queued_writer message = queue.get() File "/usr/local/sbin/python3.7/lib/python3.7/multiprocessing/queues.py", line 354, in get return _ForkingPickler.loads(res) File "/home/stamp/.local/share/virtualenvs/backend-qOgQL7Z8/lib/python3.7/site-packages/loguru/_recattrs.py", line 77, in _from_pickled_value value = pickle.loads(pickled_value) TypeError: init() missing 1 required positional argument: 'reason' --- End of logging error ---

TommeyChang avatar Oct 30 '20 07:10 TommeyChang

Hi.

This is likely a problem when enqueue=True due to some logged exception not being (un)picklable. This issue has been reported in #342 and will be fixed in the next release.

If you know where the error is coming from, you can try a workaround like this one:

try:
    faulty_function()
except Exception:
    type, _, tb = sys.exc_info()
    logger.opt(exception=(type, None, tb)).error("An error occurred")

Otherwise, you need to patch the logger like that:

def patcher(record):
    exception = record["exception"]
    if exception is not None:
        fixed = Exception(str(exception.value))
        record["exception"] = exception._replace(value=fixed)

logger.configure(patcher=patcher)

Delgan avatar Oct 30 '20 10:10 Delgan

Closing as this issue has been fixed on master branch.

Delgan avatar Sep 01 '23 11:09 Delgan