Better error handling when blob transfer fail
authorEdouard Tisserant
Wed, 10 Jul 2019 11:21:13 +0200
changeset 2621 af09744a468e
parent 2620 063391cd313d
child 2622 e10a1095f577
Better error handling when blob transfer fail
ProjectController.py
connectors/ConnectorBase.py
--- a/ProjectController.py	Wed Jul 10 10:43:14 2019 +0200
+++ b/ProjectController.py	Wed Jul 10 11:21:13 2019 +0200
@@ -1875,40 +1875,43 @@
         # note: this would abord any runing transfer with error
         self._connector.PurgeBlobs()
 
-        # transfer extra files
-        extrafiles = []
-        for extrafilespath in [self._getExtraFilesPath(),
-                               self._getProjectFilesPath()]:
-
-            for name in os.listdir(extrafilespath):
-                extrafiles.append((
-                    name,
-                    self._connector.BlobFromFile(
-                        # use file name as a seed to avoid collisions
-                        # with files having same content
-                        os.path.join(extrafilespath, name), name)))
-
-        # Send PLC on target
-        object_path = builder.GetBinaryPath()
-        # arbitrarily use MD5 as a seed, could be any string
-        object_blob = self._connector.BlobFromFile(object_path, MD5)
-
-        self.HidePLCProgress()
-
-        self.logger.write(_("PLC data transfered successfully.\n"))
-
-        if self._connector.NewPLC(MD5, object_blob, extrafiles):
-            if self.GetIECProgramsAndVariables():
-                self.UnsubscribeAllDebugIECVariable()
-                self.ProgramTransferred()
-                self.AppFrame.CloseObsoleteDebugTabs()
-                self.AppFrame.RefreshPouInstanceVariablesPanel()
-                self.AppFrame.LogViewer.ResetLogCounters()
-                self.logger.write(_("PLC installed successfully.\n"))
+        try:
+            # transfer extra files
+            extrafiles = []
+            for extrafilespath in [self._getExtraFilesPath(),
+                                   self._getProjectFilesPath()]:
+
+                for name in os.listdir(extrafilespath):
+                    extrafiles.append((
+                        name,
+                        self._connector.BlobFromFile(
+                            # use file name as a seed to avoid collisions
+                            # with files having same content
+                            os.path.join(extrafilespath, name), name)))
+
+            # Send PLC on target
+            object_path = builder.GetBinaryPath()
+            # arbitrarily use MD5 as a seed, could be any string
+            object_blob = self._connector.BlobFromFile(object_path, MD5)
+        except IOError as e:
+            self.HidePLCProgress()
+            self.logger.write_error(repr(e))
+        else:
+            self.HidePLCProgress()
+            self.logger.write(_("PLC data transfered successfully.\n"))
+
+            if self._connector.NewPLC(MD5, object_blob, extrafiles):
+                if self.GetIECProgramsAndVariables():
+                    self.UnsubscribeAllDebugIECVariable()
+                    self.ProgramTransferred()
+                    self.AppFrame.CloseObsoleteDebugTabs()
+                    self.AppFrame.RefreshPouInstanceVariablesPanel()
+                    self.AppFrame.LogViewer.ResetLogCounters()
+                    self.logger.write(_("PLC installed successfully.\n"))
+                else:
+                    self.logger.write_error(_("Missing debug data\n"))
             else:
-                self.logger.write_error(_("Missing debug data\n"))
-        else:
-            self.logger.write_error(_("PLC couldn't be installed\n"))
+                self.logger.write_error(_("PLC couldn't be installed\n"))
 
         wx.CallAfter(self.UpdateMethodsFromPLCStatus)
 
--- a/connectors/ConnectorBase.py	Wed Jul 10 10:43:14 2019 +0200
+++ b/connectors/ConnectorBase.py	Wed Jul 10 11:21:13 2019 +0200
@@ -22,3 +22,4 @@
                     return blobID
                 blobID = self.AppendChunkToBlob(chunk, blobID)
                 s.update(chunk)
+        raise IOError("Data corrupted during transfer or connection lost")