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

Internal errors when "enqueue=True" and "catch=False" should not invalidate the handler #833

Closed
Delgan opened this issue Mar 26, 2023 · 0 comments · Fixed by #834
Closed
Labels
enhancement Improvement to an already existing feature

Comments

@Delgan
Copy link
Owner

Delgan commented Mar 26, 2023

Let's say some message fail to be logged (due to Exception raised during pickling or by the sink itself). If catch=False, the Exception will be re-raised, but it the user won't be able to catch it because it's raised from a internal thread. The error will be reported on sys.stderr by Python handler, but the thread will die, thus any all the subsequent logging messages will be discarded.

import random
from loguru import logger

def broken_sink(message):
    if random.random() < 0.5:
        raise RuntimeError("Error")
    print(message, end="")

logger.remove()
logger.add(broken_sink, enqueue=True, catch=False, colorize=True)

for i in range(10):
    logger.info(f"Message #{i}")

I think this behavior is not user-friendly and does have much interest. The catch=False makes sense to let user manage exception handling, which is not possible when enqueue=True anyway.

When enqueue=False and catch=False, the caller thread will die, but the sink will remain usable by others threads. The behavior should be the same when enqueue=True.

Also, it could simplify the code.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an already existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant