diff options
author | Richard van der Hoff <richard@matrix.org> | 2017-10-11 17:26:17 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2017-10-11 17:26:17 +0100 |
commit | f30c4ed2bc2255dc7182bd026fb6437afec735a5 (patch) | |
tree | a4bd0c384afc257d0b811f2b1e060b5d1f6e74c9 /synapse/util/logformatter.py | |
parent | Fancy logformatter to format exceptions better (diff) | |
download | synapse-f30c4ed2bc2255dc7182bd026fb6437afec735a5.tar.xz |
logformatter: fix AttributeError
make sure we have the relevant fields before we try to log them.
Diffstat (limited to 'synapse/util/logformatter.py')
-rw-r--r-- | synapse/util/logformatter.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/synapse/util/logformatter.py b/synapse/util/logformatter.py index 60504162e9..cdbc4bffd7 100644 --- a/synapse/util/logformatter.py +++ b/synapse/util/logformatter.py @@ -33,9 +33,17 @@ class LogFormatter(logging.Formatter): def formatException(self, ei): sio = StringIO.StringIO() - sio.write("Capture point (most recent call last):\n") - traceback.print_stack(ei[2].tb_frame.f_back, None, sio) - traceback.print_exception(ei[0], ei[1], ei[2], None, sio) + (typ, val, tb) = ei + + # log the stack above the exception capture point if possible, but + # check that we actually have an f_back attribute to work around + # https://twistedmatrix.com/trac/ticket/9305 + + if tb and hasattr(tb.tb_frame, 'f_back'): + sio.write("Capture point (most recent call last):\n") + traceback.print_stack(tb.tb_frame.f_back, None, sio) + + traceback.print_exception(typ, val, tb, None, sio) s = sio.getvalue() sio.close() if s[-1:] == "\n": |