@@ -411,13 +411,13 @@ def filter(
411
411
"""
412
412
return Traceback (filter (fn , self ), self ._excinfo )
413
413
414
- def getcrashentry (self ) -> TracebackEntry :
414
+ def getcrashentry (self ) -> Optional [ TracebackEntry ] :
415
415
"""Return last non-hidden traceback entry that lead to the exception of a traceback."""
416
416
for i in range (- 1 , - len (self ) - 1 , - 1 ):
417
417
entry = self [i ]
418
418
if not entry .ishidden ():
419
419
return entry
420
- return self [ - 1 ]
420
+ return None
421
421
422
422
def recursionindex (self ) -> Optional [int ]:
423
423
"""Return the index of the frame/TracebackEntry where recursion originates if
@@ -602,11 +602,13 @@ def errisinstance(
602
602
"""
603
603
return isinstance (self .value , exc )
604
604
605
- def _getreprcrash (self ) -> "ReprFileLocation" :
605
+ def _getreprcrash (self ) -> Optional [ "ReprFileLocation" ] :
606
606
exconly = self .exconly (tryshort = True )
607
607
entry = self .traceback .getcrashentry ()
608
- path , lineno = entry .frame .code .raw .co_filename , entry .lineno
609
- return ReprFileLocation (path , lineno + 1 , exconly )
608
+ if entry :
609
+ path , lineno = entry .frame .code .raw .co_filename , entry .lineno
610
+ return ReprFileLocation (path , lineno + 1 , exconly )
611
+ return None
610
612
611
613
def getrepr (
612
614
self ,
@@ -942,18 +944,23 @@ def repr_excinfo(
942
944
)
943
945
else :
944
946
reprtraceback = self .repr_traceback (excinfo_ )
945
- reprcrash : Optional [ReprFileLocation ] = (
946
- excinfo_ ._getreprcrash () if self .style != "value" else None
947
- )
947
+
948
+ # will be None if all traceback entries are hidden
949
+ reprcrash : Optional [ReprFileLocation ] = excinfo_ ._getreprcrash ()
950
+ if reprcrash :
951
+ if self .style == "value" :
952
+ repr_chain += [(reprtraceback , None , descr )]
953
+ else :
954
+ repr_chain += [(reprtraceback , reprcrash , descr )]
948
955
else :
949
956
# Fallback to native repr if the exception doesn't have a traceback:
950
957
# ExceptionInfo objects require a full traceback to work.
951
958
reprtraceback = ReprTracebackNative (
952
959
traceback .format_exception (type (e ), e , None )
953
960
)
954
961
reprcrash = None
962
+ repr_chain += [(reprtraceback , reprcrash , descr )]
955
963
956
- repr_chain += [(reprtraceback , reprcrash , descr )]
957
964
if e .__cause__ is not None and self .chain :
958
965
e = e .__cause__
959
966
excinfo_ = (
@@ -1044,7 +1051,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
1044
1051
@dataclasses .dataclass (eq = False )
1045
1052
class ReprExceptionInfo (ExceptionRepr ):
1046
1053
reprtraceback : "ReprTraceback"
1047
- reprcrash : "ReprFileLocation"
1054
+ reprcrash : Optional [ "ReprFileLocation" ]
1048
1055
1049
1056
def toterminal (self , tw : TerminalWriter ) -> None :
1050
1057
self .reprtraceback .toterminal (tw )
0 commit comments