Add FatalError() method to ConfigTreeNode. svghmi
authorEdouard Tisserant
Wed, 13 Nov 2019 11:21:04 +0100
branchsvghmi
changeset 2813 ac736a878188
parent 2812 68ac5bf43525
child 2814 2cabc4773885
Add FatalError() method to ConfigTreeNode.
Extensions can report error addressed to user, without a traceback.
ConfigTreeNode.py
ProjectController.py
--- a/ConfigTreeNode.py	Thu Nov 07 16:40:48 2019 +0100
+++ b/ConfigTreeNode.py	Wed Nov 13 11:21:04 2019 +0100
@@ -670,3 +670,14 @@
                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=text(exc))
                     self.GetCTRoot().logger.write_error(msg)
                     self.GetCTRoot().logger.write_error(traceback.format_exc())
+
+
+    def FatalError(self, message):
+        """ Raise an exception that will trigger error message intended to 
+            the user, but without backtrace since it is not a software error """
+
+        raise UserAddressedException(message)
+
+class UserAddressedException(Exception):
+    pass
+
--- a/ProjectController.py	Thu Nov 07 16:40:48 2019 +0100
+++ b/ProjectController.py	Wed Nov 13 11:21:04 2019 +0100
@@ -63,7 +63,7 @@
 import targets
 from runtime.typemapping import DebugTypesSize, UnpackDebugBuffer
 from runtime import PlcStatus
-from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage
+from ConfigTreeNode import ConfigTreeNode, XSDSchemaErrorMessage, UserAddressedException
 
 base_folder = paths.AbsParentDir(__file__)
 
@@ -1171,7 +1171,10 @@
         try:
             LibCFilesAndCFLAGS, LibLDFLAGS, LibExtraFiles = self.GetLibrariesCCode(
                 buildpath)
-        except Exception:
+        except UserAddressedException as e:
+            self.logger.write_error(e.message)
+            return False
+        except Exception as e:
             self.logger.write_error(
                 _("Runtime library extensions C code generation failed !\n"))
             self.logger.write_error(traceback.format_exc())
@@ -1182,6 +1185,9 @@
             CTNLocationCFilesAndCFLAGS, CTNLDFLAGS, CTNExtraFiles = self._Generate_C(
                 buildpath,
                 self.PLCGeneratedLocatedVars)
+        except UserAddressedException as e:
+            self.logger.write_error(e.message)
+            return False
         except Exception:
             self.logger.write_error(
                 _("Runtime IO extensions C code generation failed !\n"))