@@ -1136,35 +1136,32 @@ def structured_traceback(self, etype, evalue, etb, tb_offset=None,
11361136 colorsnormal = colors .Normal # used a lot
11371137 head = '%s%s%s' % (colors .topline , '-' * min (75 , get_terminal_size ()[0 ]), colorsnormal )
11381138 structured_traceback_parts = [head ]
1139- if py3compat .PY3 :
1140- chained_exceptions_tb_offset = 0
1141- lines_of_context = 3
1142- formatted_exceptions = formatted_exception
1139+ chained_exceptions_tb_offset = 0
1140+ lines_of_context = 3
1141+ formatted_exceptions = formatted_exception
1142+ exception = self .get_parts_of_chained_exception (evalue )
1143+ if exception :
1144+ formatted_exceptions += self .prepare_chained_exception_message (evalue .__cause__ )
1145+ etype , evalue , etb = exception
1146+ else :
1147+ evalue = None
1148+ chained_exc_ids = set ()
1149+ while evalue :
1150+ formatted_exceptions += self .format_exception_as_a_whole (etype , evalue , etb , lines_of_context ,
1151+ chained_exceptions_tb_offset )
11431152 exception = self .get_parts_of_chained_exception (evalue )
1144- if exception :
1153+
1154+ if exception and not id (exception [1 ]) in chained_exc_ids :
1155+ chained_exc_ids .add (id (exception [1 ])) # trace exception to avoid infinite 'cause' loop
11451156 formatted_exceptions += self .prepare_chained_exception_message (evalue .__cause__ )
11461157 etype , evalue , etb = exception
11471158 else :
11481159 evalue = None
1149- chained_exc_ids = set ()
1150- while evalue :
1151- formatted_exceptions += self .format_exception_as_a_whole (etype , evalue , etb , lines_of_context ,
1152- chained_exceptions_tb_offset )
1153- exception = self .get_parts_of_chained_exception (evalue )
1154-
1155- if exception and not id (exception [1 ]) in chained_exc_ids :
1156- chained_exc_ids .add (id (exception [1 ])) # trace exception to avoid infinite 'cause' loop
1157- formatted_exceptions += self .prepare_chained_exception_message (evalue .__cause__ )
1158- etype , evalue , etb = exception
1159- else :
1160- evalue = None
11611160
1162- # we want to see exceptions in a reversed order:
1163- # the first exception should be on top
1164- for formatted_exception in reversed (formatted_exceptions ):
1165- structured_traceback_parts += formatted_exception
1166- else :
1167- structured_traceback_parts += formatted_exception [0 ]
1161+ # we want to see exceptions in a reversed order:
1162+ # the first exception should be on top
1163+ for formatted_exception in reversed (formatted_exceptions ):
1164+ structured_traceback_parts += formatted_exception
11681165
11691166 return structured_traceback_parts
11701167
0 commit comments