-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Audit exception handling behavior (esp RuntimeError) #2806
Comments
There's a couple of closely related issues here:
Regarding (1), I think the recently added behavior on Winforms WebView is more desirable than the current "hard crash" GTK version. That's a potential enhancement to the GTK backend (and, for that matter, the Android backend as well). The one major complication will be that the Winforms Webview failure is a configuration error - the widget will exist, and take up the relevant space; it just won't display web content. In the GTK context, we might have to put in a dummy toga.Box (or a dummy widget that has enough of an implementation to satisfy, but not implement the WebView interface). An analog of unittest.Mock() which you can call any method you want, but it won't do anything might be one approach. As for (2) and (3) - I'd argue that SystemExit is the only exception that should fully propagate and cause a termination. The rest of Toga's API is intentionally robust to programming error - clicking a button shouldn't ever cause the UI to crash - but it may cause log messages to be generated. In that context, SystemExit is the only exception that should actually kill the app, because that's literally what the exception is requesting. Anything else should be "soft reported". The only qualifier I'd put on this is whether it would be worth having a debug mode that differentiates between surfacing those errors to the log, and surfacing them to the GUI as well. I'm not 100% convinced this is desirable; on the one hand, users need to be able to report errors they're seeing, and if they're in a non-console context, they won't see console errors; but on the other hand, it could be really distracting (and confusing) for users to get stack trace dialogs in the middle of "normal" app operation. I guess the counterargument is that "normal" app operation shouldn't generate exceptions, so if they're happening that's a bug that the developer should address... I mentioned (4) specifically because I'm not completely convinced we've got exception handling for async handlers correct. Broadly, there shouldn't be any difference in error handling between sync and async handlers. However, in the recent work on Document API and Status Icons, I inevitably had some buggy code. There were a couple of occasions, especially in tests, where it looked like exceptions in asyncio handlers were being transparently swallowed. I didn't go down the rabbit hole to verify if we are missing a default exception handler on the asyncio event loop, or if the issue is the handler wrapper that is used to make handlers guaranteed async - or even to generate a replication case - but if we're taking a close look at exception handling, this would be worth looking into to ensure that there's no obvious gaps here. |
There are potentially some inconsistencies in exception handling behavior, especially as a result of WebView handling, and the handling of the Winforms asyncio event loop integration. We need to audit these interactions to ensure consistency across platforms.
Originally posted by @rmartin16 in #2781 (comment)
So, my interest remain piqued since you said this.
To recap, I had put a task on the event loop that would raise a
RuntimeError
....and all that happened was the stacktrace was printed to the console.I tracked down this behavior to
BaseEventLoop.default_exception_handler()
. If I add adefault_exception_handler()
toWinformsProactorEventLoop
, I see it run for theRuntimeError
.So, given this, what is the desired behavior when Toga itself raises an exception?
If I simulate raising the
RuntimeError
for WebView on Gtk, a console error is logged but the app window never renders.The text was updated successfully, but these errors were encountered: