[elbe-devel] [PATCH 1/1] Change exception.message to str()

Olivier Dion dion at linutronix.de
Mon Feb 3 02:24:27 CET 2020


The 'message' attribute of an exception that inherit from
BaseException is not valid in Py3.  Thus, using the '__str__' method
of the exception instead to get the error message.

See the following traceback:

----------------------------------------------------------------------
Traceback (most recent call last):

File "/home/olivier/linutronix/elbe/elbepack/debinstaller.py", \
line 237, in copy_kinitrd
download_kinitrd(tmp, suite, mirror)
File "/home/olivier/linutronix/elbe/elbepack/debinstaller.py", \
line 175, in download_kinitrd
download_release(tmp, base_url)
File "/home/olivier/linutronix/elbe/elbepack/debinstaller.py", \
line 160, in download_release
raise InvalidSignature('Failed to verify Release file')
elbepack.debinstaller.InvalidSignature: Failed to verify Release file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/olivier/linutronix/elbe/elbe", line 55, in <module>
cmdmod.run_command(sys.argv[2:])
File "/home/olivier/linutronix/elbe/elbepack/commands/init.py", \
line 198, in run_command
copy_kinitrd(xml.node("/initvm"), out_path)
File "/home/olivier/linutronix/elbe/elbepack/debinstaller.py", \
line 251, in copy_kinitrd
raise NoKinitrdException('InvalidSignature %s' % e.message)
AttributeError: 'InvalidSignature' object has no attribute 'message'
----------------------------------------------------------------------

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/commands/init.py |  5 +++--
 elbepack/debinstaller.py  |  6 +++---
 elbepack/egpg.py          | 10 +++++-----
 elbepack/soapclient.py    |  4 ++--
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
index 724babf19..a97d45dfb 100644
--- a/elbepack/commands/init.py
+++ b/elbepack/commands/init.py
@@ -197,12 +197,13 @@ def run_command(argv):
         try:
             copy_kinitrd(xml.node("/initvm"), out_path)
         except NoKinitrdException as e:
+            msg = str(e)
             logging.error("Failure to download kernel/initrd debian Package:")
             logging.error("")
-            logging.error(e.message)
+            logging.error(msg)
             logging.error("")
             logging.error("Check Mirror configuration")
-            if 'SHA256SUMS' in e.message:
+            if 'SHA256SUMS' in msg:
                 logging.error("If you use debmirror please read "
                               "https://github.com/Linutronix/elbe/issues/188 "
                               "on how to work around the issue")
diff --git a/elbepack/debinstaller.py b/elbepack/debinstaller.py
index ffe4b5421..dd882d677 100644
--- a/elbepack/debinstaller.py
+++ b/elbepack/debinstaller.py
@@ -246,8 +246,8 @@ def copy_kinitrd(prj, target_dir):
                  os.path.join(target_dir, "vmlinuz"))
 
     except IOError as e:
-        raise NoKinitrdException('IoError %s' % e.message)
+        raise NoKinitrdException('IoError %s' % str(e))
     except InvalidSignature as e:
-        raise NoKinitrdException('InvalidSignature %s' % e.message)
+        raise NoKinitrdException('InvalidSignature %s' % str(e))
     except HashValidationFailed as e:
-        raise NoKinitrdException('HashValidationFailed %s' % e.message)
+        raise NoKinitrdException('HashValidationFailed %s' % str(e))
diff --git a/elbepack/egpg.py b/elbepack/egpg.py
index 55a624e99..7cfc881f7 100644
--- a/elbepack/egpg.py
+++ b/elbepack/egpg.py
@@ -167,9 +167,9 @@ def unsign_file(fname):
         return outfilename
 
     except IOError as ex:
-        print(ex.message)
+        print(str(ex))
     except Exception as ex:
-        print("Error checking the file %s: %s" % (fname, ex.message))
+        print("Error checking the file %s: %s" % (fname, str(ex)))
 
     return None
 
@@ -195,7 +195,7 @@ def sign(infile, outfile, fingerprint):
     try:
         key = ctx.get_key(fingerprint, 0)
     except Exception as ex:
-        print("no key with fingerprint %s: %s" % (fingerprint, ex.message))
+        print("no key with fingerprint %s: %s" % (fingerprint, str(ex)))
 
     unlock_key(key.fpr)
     ctx.signers_add(key)
@@ -210,7 +210,7 @@ def sign(infile, outfile, fingerprint):
         with open(outfile, 'w') as fd:
             fd.write(signature)
     except Exception as ex:
-        print("Error signing file %s" % ex.message)
+        print("Error signing file %s" % str(ex))
 
 
 def sign_file(fname, fingerprint):
@@ -219,7 +219,7 @@ def sign_file(fname, fingerprint):
     try:
         sign(fname, outfilename, fingerprint)
     except Exception as ex:
-        print("Error signing file %s" % ex.message)
+        print("Error signing file %s" % str(ex))
 
 
 def get_fingerprints():
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index d5b18c2ca..017e015af 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -103,7 +103,7 @@ class ElbeSoapClient(object):
 
                 print("get_file part %d failed, retry %d times" % (part, retry),
                       file=sys.stderr)
-                print(e.message, file=sys.stderr)
+                print(str(e), file=sys.stderr)
                 print(repr(e.line), file=sys.stderr)
 
                 if not retry:
@@ -596,7 +596,7 @@ class WaitProjectBusyAction(ClientAction):
             # code should be reworked as soon as it's clear what is going on
             # here
             except socket.error as e:
-                print(e.message, file=sys.stderr)
+                print(str(e), file=sys.stderr)
                 print("socket error during wait busy occured, retry..",
                       file=sys.stderr)
                 continue
-- 
2.25.0




More information about the elbe-devel mailing list