Made the slot list update more resilient with respect to invalid data received by the slot signature extractor client. eric7

Sun, 04 Dec 2022 10:34:43 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 04 Dec 2022 10:34:43 +0100
branch
eric7
changeset 9558
6d6a0e5f65ca
parent 9557
4367b01cc6df
child 9559
34fc53e6159d

Made the slot list update more resilient with respect to invalid data received by the slot signature extractor client.

src/eric7/Project/CreateDialogCodeDialog.py file | annotate | diff | comparison | revisions
--- a/src/eric7/Project/CreateDialogCodeDialog.py	Sat Dec 03 14:33:56 2022 +0100
+++ b/src/eric7/Project/CreateDialogCodeDialog.py	Sun Dec 04 10:34:43 2022 +0100
@@ -331,47 +331,63 @@
 
         output, ok = self.__runUicLoadUi("signatures")
         if ok and output:
-            objectsList = json.loads(output.strip())
+            try:
+                objectsList = json.loads(output.strip())
 
-            signatureList = self.__signatures()
+                signatureList = self.__signatures()
 
-            self.slotsModel.clear()
-            self.slotsModel.setHorizontalHeaderLabels([""])
-            for objectDict in objectsList:
-                itm = QStandardItem(
-                    "{0} ({1})".format(objectDict["name"], objectDict["class_name"])
-                )
-                self.slotsModel.appendRow(itm)
-                for methodDict in objectDict["methods"]:
-                    itm2 = QStandardItem(methodDict["signature"])
-                    itm.appendRow(itm2)
+                self.slotsModel.clear()
+                self.slotsModel.setHorizontalHeaderLabels([""])
+                for objectDict in objectsList:
+                    itm = QStandardItem(
+                        "{0} ({1})".format(objectDict["name"], objectDict["class_name"])
+                    )
+                    self.slotsModel.appendRow(itm)
+                    for methodDict in objectDict["methods"]:
+                        itm2 = QStandardItem(methodDict["signature"])
+                        itm.appendRow(itm2)
+
+                        if self.__module is not None and (
+                            methodDict["methods"][0] in signatureList
+                            or methodDict["methods"][1] in signatureList
+                        ):
+                            itm2.setFlags(Qt.ItemFlag.ItemIsEnabled)
+                            itm2.setCheckState(Qt.CheckState.Checked)
+                            if ericApp().usesDarkPalette():
+                                itm2.setForeground(QBrush(QColor("#75bfff")))
+                            else:
+                                itm2.setForeground(QBrush(Qt.GlobalColor.blue))
+                            continue
 
-                    if self.__module is not None and (
-                        methodDict["methods"][0] in signatureList
-                        or methodDict["methods"][1] in signatureList
-                    ):
-                        itm2.setFlags(Qt.ItemFlag.ItemIsEnabled)
-                        itm2.setCheckState(Qt.CheckState.Checked)
-                        if ericApp().usesDarkPalette():
-                            itm2.setForeground(QBrush(QColor("#75bfff")))
-                        else:
-                            itm2.setForeground(QBrush(Qt.GlobalColor.blue))
-                        continue
+                        itm2.setData(methodDict["pyqt_signature"], pyqtSignatureRole)
+                        itm2.setData(
+                            methodDict["python_signature"], pythonSignatureRole
+                        )
+                        itm2.setData(methodDict["return_type"], returnTypeRole)
+                        itm2.setData(
+                            methodDict["parameter_types"], parameterTypesListRole
+                            )
+                        itm2.setData(
+                            methodDict["parameter_names"], parameterNamesListRole
+                        )
 
-                    itm2.setData(methodDict["pyqt_signature"], pyqtSignatureRole)
-                    itm2.setData(methodDict["python_signature"], pythonSignatureRole)
-                    itm2.setData(methodDict["return_type"], returnTypeRole)
-                    itm2.setData(methodDict["parameter_types"], parameterTypesListRole)
-                    itm2.setData(methodDict["parameter_names"], parameterNamesListRole)
+                        itm2.setFlags(
+                            Qt.ItemFlag.ItemIsUserCheckable
+                            | Qt.ItemFlag.ItemIsEnabled
+                            | Qt.ItemFlag.ItemIsSelectable
+                        )
+                        itm2.setCheckState(Qt.CheckState.Unchecked)
 
-                    itm2.setFlags(
-                        Qt.ItemFlag.ItemIsUserCheckable
-                        | Qt.ItemFlag.ItemIsEnabled
-                        | Qt.ItemFlag.ItemIsSelectable
-                    )
-                    itm2.setCheckState(Qt.CheckState.Unchecked)
-
-            self.slotsView.sortByColumn(0, Qt.SortOrder.AscendingOrder)
+                self.slotsView.sortByColumn(0, Qt.SortOrder.AscendingOrder)
+            except json.JSONDecodeError as err:
+                EricMessageBox.critical(
+                    self,
+                    self.tr("Update Slots List"),
+                    self.tr(
+                        "<p>The update of the slots list failed because invalid data"
+                        " was received.</p><p>Error: {0}</p><p>Data: {1}</p>"
+                    ).format(str(err), output),
+                )
 
     def __generateCode(self):
         """

eric ide

mercurial