Fix duplicated exception chain output for exceptions without a traceback - #14781
Fix duplicated exception chain output for exceptions without a traceback#14781SemTiOne wants to merge 2 commits into
Conversation
Co-authored-by: Claude <noreply@anthropic.com>
93a91a0 to
be30f69
Compare
Co-authored-by: Claude <noreply@anthropic.com>
be30f69 to
79df156
Compare
|
Hello @RonnyPfannschmidt, I would like you to take a look at this PR when you have a moment please. Let me know if you have any feedback. Thank you for your time 🙏 |
| # Fallback to native repr if the exception doesn't have a traceback: | ||
| # ExceptionInfo objects require a full traceback to work. | ||
| reprtraceback = ReprTracebackNative(format_exception(type(e), e, None)) | ||
| reprtraceback = ReprTracebackNative( |
There was a problem hiding this comment.
am i understanding it correct that this bandaids our lack of proper walking with disabling chaining to prevent running out of it
i think this works as a initial fix but needs a followup with more substantial work in excinfo wrt handling more detailed traces
There was a problem hiding this comment.
Yep, I agree this is a bandaid.
I wonder if we should make the traceback optional in ExceptionInfo? Or, perhaps we add a lightweight chain member representation? With repr_excinfo as the one and only chain walker, no native format_exception fallback is needed for traceback-less members. The ExceptionGroup fallback stays native for now and we no longer need the chain=False workaround. What do you think @RonnyPfannschmidt?
There was a problem hiding this comment.
I haven't actually ever dubbed to deep into that domain (most exceptions I have to handle are simple
So I'm not familiar with the developer experience and I'm of the opinion that someone that deals with tricky exceptions is more qualified to answer this
Perhaps @Zach-HD can chime in
When an exception in a chain has no
__traceback__of its own,repr_excinfo()falls back totraceback.format_exception(), which defaults tochain=Trueand walks the rest of the chain itself, duplicating what pytest's own chain-walking loop then prints again right after.Fix: pass
chain=Falseto that fallback call.Co-authored-bycommit trailers.changelogdirectory, with a name like<ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.AUTHORSin alphabetical order.