question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coroutine sink exceptions are not caught

See original GitHub issue

It appears that if you use a coroutine as a sink and it has an unhandled exception, even with catch=True specified in add(), the exception is not caught, and you will get a Task exception was never retrieved error on stderr from asyncio: https://docs.python.org/3/library/asyncio-dev.html#detect-never-retrieved-exceptions

import asyncio
from loguru import logger

async def sink(msg):
  raise Exception("oh no")

async def main():
  logger.add(sink, catch=True)
  logger.info("hello world")

asyncio.run(main())

2020-03-23 12:31:58.236 | INFO | main:main:3 - hello world Task exception was never retrieved future: <Task finished name=‘Task-2’ coro=<sink() done, defined at <stdin>:1> exception=Exception(‘oh no’)> Traceback (most recent call last): File “<stdin>”, line 2, in sink Exception: oh no

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Delgancommented, Apr 23, 2020

Fixed in next version. 😃

0reactions
Delgancommented, Mar 26, 2020

Great, so we agree on how this should behave. 👍

I’m a little worried about the callback overhead but I don’t see any other simple solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceptions in coroutines. Cancellation and Exceptions in…
When a coroutine fails with an exception, it will propagate said exception up to its parent! Then, the parent will 1) cancel the...
Read more >
Exception not being caught in Coroutines - Stack Overflow
Trying with CoroutineExceptionHandler can be workaround for handling exceptions inside coroutines. CoroutineExceptionHandler context element ...
Read more >
Exception Handling in Kotlin Coroutines EXPLAINED - YouTube
Get the full 15+ hour-long Course "Kotlin Coroutines and Flow for Android Development" with a nice discount here: ...
Read more >
C++ boost::coroutine::exception - CPPSECRETS
Name Views Likes C++ boost::utility::noncopyable 284 0 C++ boost::coroutine::passing values to Coroutine 231 6 C++ boost::intrusive::pop_back() 255 0
Read more >
Chapter 51. Boost.Coroutine - The Boost C++ Libraries
While source in main() represents the coroutine cooperative() , sink in ... be caught. Thus, exceptions are no different than with regular function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found