gpdb icon indicating copy to clipboard operation
gpdb copied to clipboard

Python: Exception has no attribute 'message'

Open gfphoenix78 opened this issue 3 years ago • 2 comments

Greenplum version or build

GPDB master, python3

Description

In some python code, the function wants to get the message of the Exception, but the Exception object doesn't have an attribute message. The Exception in python2 does have the attribute message, but python3 doesn't. It's better to use str()

diff --git a/gpMgmt/sbin/gpconfig_helper.py b/gpMgmt/sbin/gpconfig_helper.py
index a7e3b25..ff5e2cf 100755
--- a/gpMgmt/sbin/gpconfig_helper.py
+++ b/gpMgmt/sbin/gpconfig_helper.py
@@ -126,7 +126,7 @@ def main():
             return
         except Exception as err:
             sys.stderr.write("Failed to get value for parameter '%s' in file %s due to: %s" % (
-                options.get_parameter, options.file, err.message))
+                options.get_parameter, options.file, str(err)))
             sys.exit(1)

     if options.remove_parameter:
@@ -135,7 +135,7 @@ def main():
             return
         except Exception as err:
             sys.stderr.write("Failed to remove parameter '%s' in file %s due to: %s" %
-                             (options.remove_parameter, options.file, err.message))
+                             (options.remove_parameter, options.file, str(err)))
             sys.exit(1)

     if options.add_parameter:
@@ -145,7 +145,7 @@ def main():
             return
         except Exception as err:
             sys.stderr.write("Failed to add parameter '%s' in file %s due to: %s" %
-                             (options.add_parameter, options.file, err.message))
+                             (options.add_parameter, options.file, str(err)))
             sys.exit(1)

gfphoenix78 avatar Jul 13 '21 09:07 gfphoenix78

@Nirali13 Maybe we need a tool to dig out all these references, so the exceptions can be reported.

gfphoenix78 avatar Jul 13 '21 09:07 gfphoenix78

@Nirali13 Maybe we need a tool to dig out all these references, so the exceptions can be reported.

Agree. We need to have some kind of python linter to be run to detect and fix all these dangling Python3 related issues. Please lets track it as MUST complete item for GPDB7 release.

ashwinstar avatar Jul 13 '21 17:07 ashwinstar