zulip / zulip-terminal

Official Zulip terminal client.
Apache License 2.0
661 stars 252 forks source link

Crash due to KeyError exception #1271

Open jonjensen opened 1 year ago

jonjensen commented 1 year ago

Sorry to be a pest, but I've had two cases of another error happen today. This time zulip-term doesn't crash, but it shows a TUI modal on the screen:

NOTICE

An exception occurred:

KeyError: 225

The application should continue functioning, but you may notice inconsistent
behavior in this session.

Please report this to us either in
* the #zulip-terminal stream
  (https://chat.zulip.org/#narrow/stream/206-zulip-terminal in the webapp)
* an issue at https://github.com/zulip/zulip-terminal/issues

Details of the exception can be found in zulip-terminal-thread-exceptions.log

When I press escape it goes away and the program keeps working seemingly fine.

The contents of that log file:

Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1536, in _handle_message_event
    set_count([message["id"]], self.controller, 1)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1715, in _handle_update_message_flags_event
    set_count(
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1536, in _handle_message_event
    set_count([message["id"]], self.controller, 1)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1536, in _handle_message_event
    set_count([message["id"]], self.controller, 1)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1715, in _handle_update_message_flags_event
    set_count(
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1536, in _handle_message_event
    set_count([message["id"]], self.controller, 1)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1715, in _handle_update_message_flags_event
    set_count(
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1536, in _handle_message_event
    set_count([message["id"]], self.controller, 1)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225
Traceback (most recent call last):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1924, in poll_for_events
    self.event_actions[event["type"]](event)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 1715, in _handle_update_message_flags_event
    set_count(
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 267, in set_count
    _set_count_in_view(controller, new_count, changed_messages, unread_counts)
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/helper.py", line 233, in _set_count_in_view
    if controller.model.is_muted_topic(stream_id, msg_topic):
  File "/home/jon/zt_venv/lib64/python3.10/site-packages/zulipterminal/model.py", line 879, in is_muted_topic
    stream_name = self.stream_dict[stream_id]["name"]
KeyError: 225

Both times this happened to me I wasn't actively using that terminal window, but I may have typed something odd passing it as I changed virtual desktops in Awesome window manager.

The terminal I'm using is Alacritty.

neiljp commented 1 year ago

@jonjensen Thanks for another report :+1:

Are you receiving a lot of popups, or is this over an extended time? As the popup states, these issues are normally not a problem, as you've likely seen if using ZT afterwards. In any case, unless you have state stored in eg. the single draft, it's safe to simply close and restart ZT - it'll fetch state from the server each time, by default a lot less than the web client.

In terms of why this is happening...

This sequence of calls (same each time?) should only be happening when you read a message - on any client, since ZT receives an event to say that it's happened.

I suspect the issue here is that a message is being marked read in a stream that ZT isn't aware you're subscribed to, at least with its current data model.

My prime suspect is if you've subscribed to a stream in another client, while ZT was open, and read messages in that stream outside of ZT, ZT tries to process the associated read-message events and is getting confused.

Many established ZT users likely don't run into these issues, since their subscribed streams are less likely to change over time.

In any case, there are events ZT can handle for adding and removing subscriptions, and we have a WIP PR for this.

neiljp commented 1 year ago

This appears to be similar to #816, and might be fixed by #851.

jonjensen commented 1 year ago

@neiljp Thanks. The dialog box popped up twice today separated by a few hours. My subscribed streams don't typically change much for weeks at a time, but today I did delete several streams from the web client while zulip-term was also connected, and another user created a new stream, so maybe one or both of those changes was the cause.