@@ -411,13 +411,13 @@ def filter(
411411 """
412412 return Traceback (filter (fn , self ), self ._excinfo )
413413
414- def getcrashentry (self ) -> TracebackEntry :
414+ def getcrashentry (self ) -> Optional [ TracebackEntry ] :
415415 """Return last non-hidden traceback entry that lead to the exception of a traceback."""
416416 for i in range (- 1 , - len (self ) - 1 , - 1 ):
417417 entry = self [i ]
418418 if not entry .ishidden ():
419419 return entry
420- return self [ - 1 ]
420+ return None
421421
422422 def recursionindex (self ) -> Optional [int ]:
423423 """Return the index of the frame/TracebackEntry where recursion originates if
@@ -602,11 +602,13 @@ def errisinstance(
602602 """
603603 return isinstance (self .value , exc )
604604
605- def _getreprcrash (self ) -> "ReprFileLocation" :
605+ def _getreprcrash (self ) -> Optional [ "ReprFileLocation" ] :
606606 exconly = self .exconly (tryshort = True )
607607 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
610612
611613 def getrepr (
612614 self ,
@@ -942,18 +944,23 @@ def repr_excinfo(
942944 )
943945 else :
944946 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 )]
948955 else :
949956 # Fallback to native repr if the exception doesn't have a traceback:
950957 # ExceptionInfo objects require a full traceback to work.
951958 reprtraceback = ReprTracebackNative (
952959 traceback .format_exception (type (e ), e , None )
953960 )
954961 reprcrash = None
962+ repr_chain += [(reprtraceback , reprcrash , descr )]
955963
956- repr_chain += [(reprtraceback , reprcrash , descr )]
957964 if e .__cause__ is not None and self .chain :
958965 e = e .__cause__
959966 excinfo_ = (
@@ -1037,7 +1044,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
10371044@attr .s (eq = False , auto_attribs = True )
10381045class ReprExceptionInfo (ExceptionRepr ):
10391046 reprtraceback : "ReprTraceback"
1040- reprcrash : "ReprFileLocation"
1047+ reprcrash : Optional [ "ReprFileLocation" ]
10411048
10421049 def toterminal (self , tw : TerminalWriter ) -> None :
10431050 self .reprtraceback .toterminal (tw )
0 commit comments