Uninett / zinolib

Python library for zino
Apache License 2.0
1 stars 3 forks source link

Raise better error when EventManager-session and/or UpdateHandler is None #68

Open podliashanyk opened 3 months ago

podliashanyk commented 3 months ago

If connection to Zino server is lost and when client is attempting several requests after that, an AttributeError is raised. One of the errors that more clearly indicates a connection loss should be raised instead. Possibly some extra handling of session becoming None could be needed in zinolib, not sure. Same applies to UpdateHandler when it becomes None after a connection loss.

When session in EventManager is None:

Traceback (most recent call last):
  File "/Users/ilopod/Desktop/zino-dev/Howitz/howitzvenv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/ilopod/Desktop/zino-dev/Howitz/howitzvenv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/ilopod/Desktop/zino-dev/Howitz/src/howitz/endpoints.py", line 515, in refresh_events
    removed_events, modified_events, added_events, event_list = refresh_current_events()
  File "/Users/ilopod/Desktop/zino-dev/Howitz/src/howitz/endpoints.py", line 217, in refresh_current_events
    event_ids = update_events()
  File "/Users/ilopod/Desktop/zino-dev/Howitz/src/howitz/endpoints.py", line 203, in update_events
    updated = current_app.updater.get_event_update()
  File "/Users/ilopod/Desktop/zino-dev/zinolib/src/zinolib/controllers/zino1.py", line 179, in get_event_update
    self.check_connection()
  File "/Users/ilopod/Desktop/zino-dev/zinolib/src/zinolib/controllers/zino1.py", line 160, in check_connection
    if self.manager.session.push._sock.fileno() >= 0:
AttributeError: 'NoneType' object has no attribute 'push'

When UpdateHandler is None:

Traceback (most recent call last):
  File "/home/howitz/.venv/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/howitz/.venv/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/howitz/Howitz/src/howitz/endpoints.py", line 366, in refresh_events
    removed_events, modified_events, added_events = refresh_current_events()
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/howitz/Howitz/src/howitz/endpoints.py", line 156, in refresh_current_events
    event_ids = update_events()
                ^^^^^^^^^^^^^^^
  File "/home/howitz/Howitz/src/howitz/endpoints.py", line 140, in update_events
    updated = current_app.updater.get_event_update()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get_event_update'
hmpf commented 3 months ago

This means either that the UpdateHandler was never set up correctly, or that the connection was lost, cleaned up, and the reconnect failed.