Skip to content

Commit b2356d1

Browse files
committed
Be more verbose in Connect() and SendCommand(), cleanup telnet wording
Catch and log exception types during socket connect, initial LCDproc init and command submission, so users get a more proper pointer on what's wrong instead of just "Connect failed. Retry in..." or something like "Telnet exception". While at it, clean up mentions of telnet after telnetlib isn't used anymore.
1 parent e3ddcaf commit b2356d1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

resources/lib/lcdproc.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ def SendCommand(self, strCmd, bCheckRet):
7474
sendcmd += b"\n"
7575

7676
try:
77-
# Send to server via raw socket to prevent telnetlib tampering with
78-
# certain chars (especially 0xFF -> telnet IAC)
77+
# Send commands to LCDproc server
7978
self.m_socket.sendall(sendcmd)
80-
except:
79+
except Exception as ex:
8180
# Something bad happened, abort
82-
log(LOGERROR, "SendCommand: Telnet exception - send")
81+
log(LOGERROR, "SendCommand(): Caught %s on m_socket.sendall()" % type(ex))
8382
return False
8483

8584
# Update last socketaction timestamp
@@ -92,9 +91,9 @@ def SendCommand(self, strCmd, bCheckRet):
9291
try:
9392
# Read server reply
9493
reply = self.ReadUntil(b"\n")
95-
except:
94+
except Exception as ex:
9695
# (Re)read failed, abort
97-
log(LOGERROR, "SendCommand: Telnet exception - reread")
96+
log(LOGERROR, "SendCommand(): Caught %s when reading back response(s)" % type(ex))
9897
return False
9998

10099
# Skip these messages
@@ -273,6 +272,11 @@ def Connect(self):
273272
self.m_socket.connect((ip, port))
274273
self.m_socket.settimeout(3)
275274

275+
except Exception as ex:
276+
log(LOGERROR, "Connect(): Caught %s on initial connect, aborting" % type(ex))
277+
return False
278+
279+
try:
276280
# Start a new session
277281
self.m_socket.send(b"hello\n")
278282

@@ -315,8 +319,8 @@ def Connect(self):
315319
# (might override e.g. m_iBigDigits!)
316320
self.DetermineExtraSupport()
317321

318-
except:
319-
log(LOGERROR,"Connect: Caught exception, aborting.")
322+
except Exception as ex:
323+
log(LOGERROR,"Connect(): Caught %s during hello/info phase, aborting." % type(ex))
320324
return False
321325

322326
if not self.SetupScreen():

0 commit comments

Comments
 (0)