MythTV / mythtv

The official MythTV repository
https://www.mythtv.org
GNU General Public License v2.0
706 stars 346 forks source link

Python bindings MythTV.MythError.CLOSEDSOCKET does not exist #423

Closed fe31nz closed 2 years ago

fe31nz commented 2 years ago

What steps will reproduce the bug?

I am writing a Python program (epgdiff) that uses the frontend API to navigate mythfrontend screens. During testing, I had my program connected to mythfrontend and then tried shutting down mythfrontend to see how my program would cope with that. When the socket connection to mythfrontend was closed, I got an exception from the libmyth-python code, as expected, but that exception caused another AttributeError exception because the name of the original exception was not defined anywhere.

The socket closed exception is generated in utitlity/other.py at line 374:

raise MythError(MythError.CLOSEDSOCKET)

But MythTV.MythError.CLOSEDSOCKET is undefined. I think it should be defined in "class ERRCODES( object ):" at line 225 in static.py, or perhaps it should be handled the same way as other exceptions in other.py, as MythError.SOCKET and a specific message.

What do you see instead?

stephen@mypvr:~/.mythtv$ epgdiff -G -l -i 1001 1002 1003 02:08:29.943 epgdiff debug output started 02:08:30.101 Existing epgdiff window not found 02:08:30.101 config_xml="" 02:08:32.787 self.first_programme=' Big Fat Gypsy Weddings' 02:08:42.736 event='Return:36' values={'selected': [' Big Fat Gypsy Weddings']} 02:08:42.736 Return 02:08:42.736 search_for_title: title='Big Fat Gypsy Weddings' 02:08:42.736 jumppoint: mainmenu 02:08:42.736 handle_event_loop_task_result: task=<Task finished name='Task-2' coro=<GUI.event_loop() done, defined at /usr/local/bin/epgdiff:1026> exception=AttributeError("type object 'MythError' has no attribute 'CLOSEDSOCKET'")> 02:08:42.736 handle_event_loop_task_result: e=AttributeError("type object 'MythError' has no attribute 'CLOSEDSOCKET'") Traceback (most recent call last): File "/usr/local/bin/epgdiff", line 1111, in w.main() File "/usr/local/bin/epgdiff", line 1105, in main asyncio.run(self.run()) File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/usr/local/bin/epgdiff", line 1098, in run await asyncio.gather(self.get_lines_task, event_loop_task) File "/usr/local/bin/epgdiff", line 1058, in event_loop self.search_for_title(self.content[self.line_no][PLPL:]) File "/usr/local/bin/epgdiff", line 888, in search_for_title self.gotoTitleSearch() File "/usr/local/bin/epgdiff", line 876, in gotoTitleSearch self.do_jump('mainmenu', 'mainmenu') File "/usr/local/bin/epgdiff", line 851, in do_jump if not self.fe.jump[jumppoint]: File "/usr/lib/python3/dist-packages/MythTV/methodheap.py", line 546, in getitem self._populate() File "/usr/lib/python3/dist-packages/MythTV/methodheap.py", line 543, in _populate self._points = dict(self._parent.send('jump')) File "/usr/lib/python3/dist-packages/MythTV/connections.py", line 546, in send res = self.recv() File "/usr/lib/python3/dist-packages/MythTV/connections.py", line 558, in recv res = self.socket.dlexpect(prompt, deadline=deadline) File "/usr/lib/python3/dist-packages/MythTV/utility/other.py", line 374, in dlexpect raise MythError(MythError.CLOSEDSOCKET) AttributeError: type object 'MythError' has no attribute 'CLOSEDSOCKET'

rcrdnalor commented 2 years ago

MythTV/utility/other.py : class deadlinesocket

If there is no data available from the socket, the method 'deadlinesocket.dlexpect()' should raise the same error as the method 'deadlinesocket.dlrecv()':

raise MythError(MythError.SOCKET, (54, 'Connection reset by peer')) instead of raise MythError(MythError.CLOSEDSOCKET)

NB, the number 54 should be 104 for the Error 'Connection reset by peer'.

Could you test this change?

fe31nz commented 2 years ago

Yes, that fixes the problem.