loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Loguru catch function parameters

Open david-shiko opened this issue 3 years ago • 3 comments

Why does Loguru.logger.catch doesn't pass original function parameters to the wrapped function?

david-shiko avatar May 29 '22 21:05 david-shiko

I think it does:

>>> from loguru import logger
>>> @logger.catch
... def add(a, b):
...   return a + b
...
>>> add(1, 2)
3

Do you have an example where it's not the case?

Delgan avatar May 29 '22 22:05 Delgan

I think it does:

>>> from loguru import logger
>>> @logger.catch
... def add(a, b):
...   return a + b
...
>>> add(1, 2)
3

Do you have an example where it's not the case?

Sorry, I mean to get access to parameters inside on_error function.

david-shiko avatar May 30 '22 07:05 david-shiko

@david-shiko The onerror argument exists to help with error handling. If an unexpected error occurs, you may want to call sys.exit() with a different code based on error type for example. It's not meant for very advanced usages, if you need different behaviors based on function parameters, I would suggest to use a good old try / except block inside your function.

Delgan avatar May 30 '22 11:05 Delgan

I'm closing the issue as it seems answered. Feel free to re-open it if you need more help.

Delgan avatar Oct 09 '22 09:10 Delgan