This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cgitb gives wrong lineno inside try:..finally:
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, georg.brandl, hooft
Priority: normal Keywords:

Created on 2005-08-03 12:54 by hooft, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg25963 - (view) Author: Rob W.W. Hooft (hooft) Date: 2005-08-03 12:54
If an error occurs in a try: finally: block, the normal
traceback prints the correct line number, but the cgitb
module prints the error as if it occurred in the last
line of the finally: block.

Example code:
====================
import cgitb
cgitb.enable()

try:
    0//0
finally:
    print "This is not where the exception occurred!"
=====================

Traceback correctly reports the error in line 5, but
cgitb reports line 7.

I am using python-2.3.4 on Debian/Linux.

Probable cause: the inspect module, in getframeinfo,
uses the f_lineno attribute  from the frame object.
This is what is printed in the cgitb trace. The
traceback module uses the tb_lineno object of the
traceback object itself, which is correct.

Workaround: I am now working around this by using
tb.tb_lineno in inspect.getframeinfo if a traceback
object was passed, and f.f_lineno if a frame object was
passed. I do not have sufficient insight in the code to
foresee any other problems with this fix.




msg82195 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-16 00:45
Cannot reproduce, trunk as of rev69550 displays the error highlighted in
the correct line.
msg85532 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 17:29
Works for me as well.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42247
2009-04-05 17:29:56georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg85532

resolution: works for me
2009-02-16 00:45:32ajaksu2settype: behavior
stage: test needed
messages: + msg82195
nosy: + ajaksu2
versions: + Python 2.6
2005-08-03 12:54:13hooftcreate