Bug 716435

Summary: Tracebacks should contain the first line of continuation lines
Product: Red Hat Enterprise Linux 6 Reporter: Petr Šplíchal <psplicha>
Component: pythonAssignee: Dave Malcolm <dmalcolm>
Status: CLOSED WONTFIX QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1CC: ohudlick
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-07-01 00:15:04 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Petr Šplíchal 2011-06-24 12:30:32 UTC
Description of problem:

Currently, python tracebacks shows the last of continuation lines
when a function spans across multiple lines. This line usually
contains some function parameter only and thus is not very useful
for debugging the problem.

For example:

    Traceback (most recent call last):
    File "./tcms-run", line 48, in <module>
        summary=options.summary)
    File "/home/psss/git/tcms/Nitrate.py", line 600, in __init__
        raise NitrateError("Need either id or test plan")

If the traceback contained the beginning of the continuation line
it would be IMHO much more clear where/how the problem happened.

    Traceback (most recent call last):
    File "./tcms-run", line 48, in <module>
        run = TestRun(plan=plan, distro=options.distro,
    File "/home/psss/git/tcms/Nitrate.py", line 600, in __init__
        raise NitrateError("Need either id or test plan")

Version-Release number of selected component (if applicable):
python-2.6.6-20.el6.x86_64

Trivial reproducer:

    def fun1(par):
        raise Exception
    def fun2():
        fun1(
                par="value")
    fun2()

Actual results:

    Traceback (most recent call last):
    File "/tmp/traceback.py", line 10, in <module>
        fun2()
    File "/tmp/traceback.py", line 8, in fun2
        par="value")
    File "/tmp/traceback.py", line 4, in fun1
        raise Exception
    Exception

Comment 1 Dave Malcolm 2011-07-01 00:11:33 UTC
The printing code in question is within Python/traceback.c
It uses the tb->tb_lineno of a PyTracebackObject to determine which line to print, and tb_lineno is in fact exposed to Python code; see:
  http://docs.python.org/library/traceback.html

It's set up in newtracebackobject (called by PyTraceBack_Here(PyFrameObject *frame)) based on the last bytecode being executed within the frame:

     PyCode_Addr2Line(frame->f_code,
                      frame->f_lasti)

Comment 3 RHEL Program Management 2011-07-01 00:15:04 UTC
Development Management has reviewed and declined this request.  You may appeal
this decision by reopening this request.

Comment 4 Petr Šplíchal 2011-07-01 05:49:18 UTC
OK, filed upstream as: http://bugs.python.org/issue12458