prompt-toolkit/python-prompt-toolkit

bug/feature: Silent Exceptions in Keybinding Event Handlers

Closed this issue · 4 comments

When a keybinding event handler raises an exception, it seems to be "swallowed" silently by the application, causing difficult-to-trace bugs. Ideally, exceptions raised within keybinding event handlers should either be propagated or logged, allowing for better debugging and error handling.

Steps to reproduce:

Add a keybinding event handler that intentionally raises an exception.
Run the application and trigger the keybinding.
Observe that the exception does not surface or get logged, and the application continues as if nothing happened.
Expected behavior: Exceptions within keybinding event handlers should either be displayed, logged, or propagated, rather than being silently ignored.

Regards,
Z

Have you maybe disabled the exception handling in your app? If yes you'll need to set up your own handling of exceptions to catch them or enable the handling back

No, I haven't. Maybe it has something to do with async coroutine?

Try to disable the exception handling, see if it gets printed. It's the set_exception_handler argument in Application.

Here's how it works too


def set_exception_handler_ctx(loop: AbstractEventLoop) -> Iterator[None]:

Thanks for the hint, will have a look at it. Indeed in the example applications the exception is displayed. My wrong.

The problem is somewhere in my async loop management. If it turns out that something can be improved this related I will let you know.