src/eric7/MicroPython/MicroPythonWebreplSocket.py

branch
eric7
changeset 10229
e50bbf250343
parent 10017
6d5ba2c97a8a
child 10428
a071d4065202
--- a/src/eric7/MicroPython/MicroPythonWebreplSocket.py	Thu Oct 05 17:07:35 2023 +0200
+++ b/src/eric7/MicroPython/MicroPythonWebreplSocket.py	Fri Oct 06 15:52:33 2023 +0200
@@ -113,8 +113,8 @@
         @type str
         @param port port number
         @type int
-        @return flag indicating success
-        @rtype bool
+        @return flag indicating success and an error message
+        @rtype tuple of (bool, str)
         """
         if self.__connected:
             self.disconnectFromDevice()
@@ -123,10 +123,10 @@
         self.open(url)
         ok = self.waitForConnected()
         if not ok:
-            return False
+            return False, self.tr("Connection to device webrepl failed.")
 
         self.__connected = True
-        return True
+        return True, ""
 
     def disconnect(self):
         """
@@ -160,14 +160,19 @@
 
         @param password password
         @type str
-        @return flag indicating a successful login
-        @rtype bool
+        @return flag indicating a successful login and an error indication
+        @rtype tuple of (bool, str)
         """
         self.readUntil(expected=b": ")
         self.writeTextMessage(password.encode("utf-8") + b"\r")
         data = self.readUntil([b">>> ", b"denied\r\n"])
+        error = (
+            self.tr("WebRepl login failed (access denied).")
+            if data.endswith(b"denied\r\n")
+            else ""
+        )
 
-        return not data.endswith(b"denied\r\n")
+        return error == "", error
 
     def writeTextMessage(self, data):
         """

eric ide

mercurial