ImperialCollegeLondon / FINESSE

A graphical user interface for controlling and monitoring an interferometer device
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

Uncaught exceptions when connection to FTSW closes unexpectedly #539

Closed alexdewar closed 7 months ago

alexdewar commented 8 months ago

To reproduce:

  1. Start FTSW500
  2. Open connection from FINESSE using "Manage devices" dialog
  3. Close FTSW500 program window

Result:

Workaround:

The most common error seems to be this:

Traceback (most recent call last):
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 196, in _request_status
    self.request_command(b"getFTSW500State\n")
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 204, in request_command
    self._make_request(command)
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 191, in _make_request
    self._requester.sendall(command)
BrokenPipeError: [Errno 32] Broken pipe

But I also sometimes see:

Traceback (most recent call last):
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 196, in _request_status
    self.request_command(b"getFTSW500State\n")
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 204, in request_command
    self._make_request(command)
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 192, in _make_request
    self._on_reply_received(self._requester.recv(1024))
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 186, in _on_reply_received
    self._regurgitate_nonmodal_dialog_message()
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 147, in _regurgitate_nonmodal_dialog_message
    if self._check_is_nonmodal_dialog_open():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/code/FINESSE/finesse/hardware/plugins/spectrometer/ftsw500_interface.py", line 131, in _check_is_nonmodal_dialog_open
    if data.decode().split("&")[1] == "true\n":
       ~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

BrokenPipeErrors should be caught with the error propagated to the fronted via a pubsub message (e.g. by using the pubsub_errors() decorator). In the second error I mention though, the code just needs to be written a bit more defensively. The send and receive operations for FTSW500Interface could possibly be encapsulated in their own functions with error handling taking place there (plus, having self._requester.recv(1024) dotted all over the place smells a bit wrong to me).

Tagging @dc2917