##// END OF EJS Templates
i1673 use __cause__ first in chained exceptions
Justyna Ilczuk -
Show More
@@ -967,17 +967,17 b' class VerboseTB(TBTools):'
967 967 info('\nUnfortunately, your original traceback can not be constructed.\n')
968 968 return None
969 969
970 def get_exception_from_context(self, evalue):
971 if hasattr(evalue, '__context__'):
972 context = evalue.__context__
973 if not context:
974 return None
975 else:
976 exception_traceback = context.__traceback__
977 exception_type = context.__class__
978 return exception_type, context, exception_traceback
979 else:
980 return None
970 def get_parts_of_chained_exception(self, evalue):
971 def get_chained_exception(exception_value):
972 cause = getattr(exception_value, '__cause__', None)
973 if cause:
974 return cause
975 return getattr(exception_value, '__context__', None)
976
977 chained_evalue = get_chained_exception(evalue)
978
979 if chained_evalue:
980 return chained_evalue.__class__, chained_evalue, chained_evalue.__traceback__
981 981
982 982 def structured_traceback(self, etype, evalue, etb, tb_offset=None,
983 983 number_of_lines_of_context=5):
@@ -994,7 +994,7 b' class VerboseTB(TBTools):'
994 994 chained_exceptions_tb_offset = 0
995 995 lines_of_context = 3
996 996 formatted_exceptions = formatted_exception
997 exception = self.get_exception_from_context(evalue)
997 exception = self.get_parts_of_chained_exception(evalue)
998 998 if exception:
999 999 formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
1000 1000 etype, evalue, etb = exception
@@ -1003,7 +1003,8 b' class VerboseTB(TBTools):'
1003 1003 while evalue:
1004 1004 formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
1005 1005 chained_exceptions_tb_offset)
1006 exception = self.get_exception_from_context(evalue)
1006 exception = self.get_parts_of_chained_exception(evalue)
1007
1007 1008 if exception:
1008 1009 formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
1009 1010 etype, evalue, etb = exception
General Comments 0
You need to be logged in to leave comments. Login now