From ae3285b6a2a5422e408fa84799db3ae4c0021bbe Mon Sep 17 00:00:00 2001 From: Oliver Wu Date: Thu, 2 Oct 2025 15:45:53 -0400 Subject: [PATCH 1/3] Add getter methods of the python exception class The code and message should be able to return. It keeps consistent with the API of C++. The naming conversion is also followed with ACT implementation rather than python PEP 8. --- Source/buildbindingpython.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/buildbindingpython.go b/Source/buildbindingpython.go index a96d4da2..ed822e8c 100644 --- a/Source/buildbindingpython.go +++ b/Source/buildbindingpython.go @@ -132,6 +132,12 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" if self._message:") w.Writeln(" return '%sException ' + str(self._code) + ': '+ str(self._message)", NameSpace) w.Writeln(" return '%sException ' + str(self._code)", NameSpace) + w.Writeln(" ") + w.Writeln(" def GetErrorCode(self):") + w.Writeln(" return self._code") + w.Writeln(" ") + w.Writeln(" def GetErrorMessage(self):") + w.Writeln(" return self._message") w.Writeln("") From 8e8bec758e341fe5ab5fbd79eec2d13ad6e462a1 Mon Sep 17 00:00:00 2001 From: Oliver Wu Date: Thu, 2 Oct 2025 16:06:21 -0400 Subject: [PATCH 2/3] Add additional methods --- Source/buildbindingpython.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/buildbindingpython.go b/Source/buildbindingpython.go index ed822e8c..7695e865 100644 --- a/Source/buildbindingpython.go +++ b/Source/buildbindingpython.go @@ -138,6 +138,26 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" ") w.Writeln(" def GetErrorMessage(self):") w.Writeln(" return self._message") + w.Writeln(" ") + w.Writeln(" def GetErrorName(self):") + w.Writeln(" if self._code == ErrorCodes.SUCCESS:") + w.Writeln(" return 'SUCCESS'") + for _, errorDef := range componentdefinition.Errors.Errors { + w.Writeln(" elif self._code == ErrorCodes.%s:", errorDef.Name) + w.Writeln(" return '%s'", errorDef.Name) + } + w.Writeln(" else:") + w.Writeln(" return 'UNKNOWN'") + w.Writeln(" ") + w.Writeln(" def GetErrorDescription(self):") + w.Writeln(" if self._code == ErrorCodes.SUCCESS:") + w.Writeln(" return 'success'") + for _, errorDef := range componentdefinition.Errors.Errors { + w.Writeln(" elif self._code == ErrorCodes.%s:", errorDef.Name) + w.Writeln(" return '%s'", errorDef.Description) + } + w.Writeln(" else:") + w.Writeln(" return 'unknown error'") w.Writeln("") From 256f970e148055bbf5cfdbd6fb61e21593e7f5d8 Mon Sep 17 00:00:00 2001 From: Oliver Wu Date: Thu, 2 Oct 2025 17:28:13 -0400 Subject: [PATCH 3/3] Add properties for the exception class It ensures Cross-Language Consistency. C++: Uses methods (getErrorCode()) C#: Uses properties (ErrorCode) Java: Uses methods (getErrorCode()) Python: Can support both patterns Meanwhile, rename the methods to comply with PEP 8 --- Source/buildbindingpython.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Source/buildbindingpython.go b/Source/buildbindingpython.go index 7695e865..31d36cf2 100644 --- a/Source/buildbindingpython.go +++ b/Source/buildbindingpython.go @@ -133,13 +133,16 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" return '%sException ' + str(self._code) + ': '+ str(self._message)", NameSpace) w.Writeln(" return '%sException ' + str(self._code)", NameSpace) w.Writeln(" ") - w.Writeln(" def GetErrorCode(self):") + w.Writeln(" def get_error_code(self):") + w.Writeln(" \"\"\"Returns the error code\"\"\"") w.Writeln(" return self._code") w.Writeln(" ") - w.Writeln(" def GetErrorMessage(self):") + w.Writeln(" def get_error_message(self):") + w.Writeln(" \"\"\"Returns the custom error message\"\"\"") w.Writeln(" return self._message") w.Writeln(" ") - w.Writeln(" def GetErrorName(self):") + w.Writeln(" def get_error_name(self):") + w.Writeln(" \"\"\"Returns the error name (constant name)\"\"\"") w.Writeln(" if self._code == ErrorCodes.SUCCESS:") w.Writeln(" return 'SUCCESS'") for _, errorDef := range componentdefinition.Errors.Errors { @@ -149,7 +152,8 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" else:") w.Writeln(" return 'UNKNOWN'") w.Writeln(" ") - w.Writeln(" def GetErrorDescription(self):") + w.Writeln(" def get_error_description(self):") + w.Writeln(" \"\"\"Returns the error description (human-readable)\"\"\"") w.Writeln(" if self._code == ErrorCodes.SUCCESS:") w.Writeln(" return 'success'") for _, errorDef := range componentdefinition.Errors.Errors { @@ -158,6 +162,26 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w } w.Writeln(" else:") w.Writeln(" return 'unknown error'") + w.Writeln(" ") + w.Writeln(" @property") + w.Writeln(" def error_code(self):") + w.Writeln(" \"\"\"Property to access error code\"\"\"") + w.Writeln(" return self._code") + w.Writeln(" ") + w.Writeln(" @property") + w.Writeln(" def error_message(self):") + w.Writeln(" \"\"\"Property to access custom error message\"\"\"") + w.Writeln(" return self._message") + w.Writeln(" ") + w.Writeln(" @property") + w.Writeln(" def error_name(self):") + w.Writeln(" \"\"\"Property to access error name\"\"\"") + w.Writeln(" return self.get_error_name()") + w.Writeln(" ") + w.Writeln(" @property") + w.Writeln(" def error_description(self):") + w.Writeln(" \"\"\"Property to access error description\"\"\"") + w.Writeln(" return self.get_error_description()") w.Writeln("")