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

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

Closed
TommeyChang opened this issue Oct 30, 2020 · 2 comments
Closed
Labels
duplicate This issue or pull request already exists

Comments

@TommeyChang
Copy link

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 ---

@Delgan
Copy link
Owner

Delgan commented Oct 30, 2020

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
Copy link
Owner

Delgan commented Sep 1, 2023

Closing as this issue has been fixed on master branch.

@Delgan Delgan closed this as completed Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants