Opened 5 months ago

Last modified 5 months ago

#9305 defect new

Failure.getTracebackObject result lacks outer stack frames

Reported by: Richard van der Hoff Owned by:
Priority: normal Milestone:
Component: core Keywords: review
Cc: Branch:


Failure.getTracebackObject constructs a fake Traceback which includes the stack frames between the point the exception was thrown and where it was caught, but doesn't include any of the frames above it. We have this information (in failure.stack), and it may be useful for debugging, so it's regrettable that it isn't included in the fake Traceback.

We ought to be able to pass the stack into traceback.print_stack, but doing so actually causes exceptions.AttributeError: '_Frame' object has no attribute 'f_lineno'.

Test program:

#!/usr/bin/env python
import traceback

import sys
from twisted.logger import globalLogBeginner, textFileLogObserver
from twisted.internet import defer


def raiser(_):
    raise Exception()

def report(failure):
    tb = failure.getTracebackObject()
    # if tb were a real Traceback, this would work

# raise an exception from a callback, but don't yet handle it
# (which prompts the Failure object to forget its real Traceback object)
d = defer.Deferred()

# now try to report it

Change History (2)

comment:1 Changed 5 months ago by Richard van der Hoff

Type: enhancementdefect

comment:2 Changed 5 months ago by Richard van der Hoff

Keywords: review added
Note: See TracTickets for help on using tickets.