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

Support inter-thread exception handling #819

Merged
merged 5 commits into from
Nov 19, 2020

Conversation

neiljp
Copy link
Collaborator

@neiljp neiljp commented Nov 3, 2020

This extends an approach originally in a commit by @amanagr some time ago to use an urwid pipe to allow exceptions to be passed across threads. This is a more general form which I've had in a branch for some time.

While this doesn't yet take this approach as far as it could go, this has some rather important benefits already, most noticeably if an exception occurs during event handling:

  • the event loop keeps running
  • the exception is logged to a file
  • a notice window is shown indicating an error occurred, where to report it and where the report is logged

The limitations in this PR right now are:

  • lack of explicit tests; this has been manually tested and appear to work fine
  • perhaps configuring the exception output to use a standard logger from run.py?

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Nov 3, 2020
This enables setting up custom loop properties before running the loop.

This also brings various member variables and setup into a central
location to make it easier to reason about and avoid possibly-None
values.

Tests amended.

Based on an inlined version of a commit by Aman Agrawal.
This adds Controller.raise_exception_in_main_thread(), which when passed
sys.exc_info() from an 'except' block in another thread raises the
corresponding exception in the controller in its thread, by using an
urwid watch_pipe callback to _raise_exception.

Based on a form without stack trace by Aman Agrawal.

Test amended.
Before this commit, exceptions in event handlers would result in a
traceback overlaid on the UI (if loaded); the application could appear
to continue as normal, but the event loop would fail - and identifying
tracebacks was challenging, as the UI might draw over the details.

This commit ensures that exceptions from event handlers are sent to the
main thread in the controller, using the infrastructure added in the
prior commit, where they are re-raised, causing the application to exit
and the exception to be logged.
This commit adds a new boolean `critical` parameter to
raise_exception_in_main_thread. If the exception event is not marked as
critical then a notice popup window is shown prompting users to report
the issue to #zulip-terminal or to the github issue page. If it is
critical, the previous behavior is retained, ie. the exception from the
other thread is raised in the main thread and the application exits.

With this new parameter set to `False`, the poll_for_events loop can
fail for one event (with a notice) but continue otherwise to allow the
application to maintain more functionality without either abruptly
exiting or not indicating that something has subtly failed.
Also explicitly return True in callback from pipe to avoid possibility
of pipe removal.

Test amended.
@neiljp neiljp force-pushed the 2020-04-29-streamline-exception-handling branch from 35cbeb3 to 5ceef99 Compare November 19, 2020 00:46
@neiljp neiljp added this to the Next Release milestone Nov 19, 2020
@neiljp neiljp added the PR ready to be merged PR has been reviewed & is ready to be merged label Nov 19, 2020
@neiljp neiljp merged commit eaa7704 into zulip:master Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR ready to be merged PR has been reviewed & is ready to be merged size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants