[tor-commits] [bridgedb/develop] Avoid use of exception 'message' attribute
phw at torproject.org
phw at torproject.org
Wed Feb 19 18:27:17 UTC 2020
commit f19bc2ac815b31672bc83a7dc39013d8d80f9eb6
Author: Damian Johnson <atagar at torproject.org>
Date: Fri Jan 10 13:54:27 2020 -0800
Avoid use of exception 'message' attribute
Addressing the following exceptions...
Traceback (most recent call last):
File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_parse_options.py", line 67, in test_parse_options_parseOptions_with_valid_options
opts = options.parseOptions()
File "/home/atagar/Desktop/tor/bridgedb/bridgedb/parse/options.py", line 125, in parseOptions
print("Unhandled Error: %s" % error.message)
builtins.AttributeError: 'AttributeError' object has no attribute 'message'
If all we want is the exception message then its string representation does the
trick.
This didn't change the test outcome much...
before: FAILED (skips=1, failures=8, errors=49, successes=254)
after: FAILED (skips=1, failures=7, errors=49, successes=255)
---
bridgedb/captcha.py | 2 +-
bridgedb/distributors/email/server.py | 2 +-
bridgedb/distributors/https/server.py | 6 +++---
bridgedb/distributors/moat/server.py | 2 +-
bridgedb/parse/options.py | 4 ++--
bridgedb/persistent.py | 4 ++--
bridgedb/translations.py | 2 +-
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/bridgedb/captcha.py b/bridgedb/captcha.py
index b66972c..5c67df0 100644
--- a/bridgedb/captcha.py
+++ b/bridgedb/captcha.py
@@ -295,7 +295,7 @@ class GimpCaptcha(Captcha):
now = int(time.time())
answer = answerBlob[12:]
except Exception as error:
- logging.warn(error.message)
+ logging.warn(str(error))
else:
# If the beginning of the 'next' interval (the interval
# after the one when the CAPTCHA timestamp was created)
diff --git a/bridgedb/distributors/email/server.py b/bridgedb/distributors/email/server.py
index 8bd4b36..5a1ffc0 100644
--- a/bridgedb/distributors/email/server.py
+++ b/bridgedb/distributors/email/server.py
@@ -499,7 +499,7 @@ def addServer(config, distributor):
reactor.listenTCP(port, factory, interface=addr)
except CannotListenError as error: # pragma: no cover
logging.fatal(error)
- raise SystemExit(error.message)
+ raise SystemExit(str(error))
# Set up a LoopingCall to run every 30 minutes and forget old email times.
lc = LoopingCall(distributor.cleanDatabase)
diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py
index 660d34e..db7e2fe 100644
--- a/bridgedb/distributors/https/server.py
+++ b/bridgedb/distributors/https/server.py
@@ -549,9 +549,9 @@ class CaptchaProtectedResource(CustomErrorHandlingResource, CSPResource):
metrix.recordValidHTTPSRequest(request)
return self.resource.render(request)
except ValueError as err:
- logging.debug(err.message)
+ logging.debug(str(err))
except MaliciousRequest as err:
- logging.debug(err.message)
+ logging.debug(str(err))
# Make them wait a bit, then redirect them to a "daring
# work of art" as pennance for their sins.
d = task.deferLater(reactor, 1, lambda: request)
@@ -559,7 +559,7 @@ class CaptchaProtectedResource(CustomErrorHandlingResource, CSPResource):
metrix.recordInvalidHTTPSRequest(request)
return NOT_DONE_YET
except Exception as err:
- logging.debug(err.message)
+ logging.debug(str(err))
metrix.recordInvalidHTTPSRequest(request)
return replaceErrorPage(request, err)
diff --git a/bridgedb/distributors/moat/server.py b/bridgedb/distributors/moat/server.py
index 97dfc42..7391325 100644
--- a/bridgedb/distributors/moat/server.py
+++ b/bridgedb/distributors/moat/server.py
@@ -602,7 +602,7 @@ class CaptchaCheckResource(CaptchaResource):
logging.warn(("Error processing client POST request: "
"Client JSON API data missing '%s' field.") % err)
except ValueError as err:
- logging.warn("Error processing client POST request: %s" % err.message)
+ logging.warn("Error processing client POST request: %s" % err)
except Exception as impossible:
logging.error(impossible)
diff --git a/bridgedb/parse/options.py b/bridgedb/parse/options.py
index e5c4d1e..0eeb79e 100644
--- a/bridgedb/parse/options.py
+++ b/bridgedb/parse/options.py
@@ -117,12 +117,12 @@ def parseOptions():
try:
options.parseOptions()
except usage.UsageError as uerr:
- print(uerr.message)
+ print(str(uerr))
print(options.getUsage())
sys.exit(1)
except Exception as error: # pragma: no cover
exc, value, tb = sys.exc_info()
- print("Unhandled Error: %s" % error.message)
+ print("Unhandled Error: %s" % error)
print(traceback.format_exc(tb))
return options
diff --git a/bridgedb/persistent.py b/bridgedb/persistent.py
index 4b077d8..89d3dd4 100644
--- a/bridgedb/persistent.py
+++ b/bridgedb/persistent.py
@@ -183,7 +183,7 @@ class State(jelly.Jellyable):
except (AttributeError, TypeError) as error:
err += "Failed statefile.open() and statefile.closed:"
err += "\n\t{0}\nstatefile type = '{1}'".format(
- error.message, type(statefile))
+ error, type(statefile))
else:
try:
status = pickle.load(fh)
@@ -218,7 +218,7 @@ class State(jelly.Jellyable):
pickle.dump(jelly.jelly(self), fh)
except AttributeError as error:
logging.debug("Tried jellying an unjelliable object: %s"
- % error.message)
+ % error)
if fh is not None:
fh.flush()
diff --git a/bridgedb/translations.py b/bridgedb/translations.py
index 6d7d332..f2b06e9 100644
--- a/bridgedb/translations.py
+++ b/bridgedb/translations.py
@@ -124,7 +124,7 @@ def installTranslations(langs):
gettext.translation("bridgedb", localedir=TRANSLATIONS_DIR,
languages=langs, fallback=True))
except IOError as error:
- logging.error(error.message)
+ logging.error(str(error))
language.install(unicode=True)
return language
More information about the tor-commits
mailing list