Make IPython show source code line where exception occurred

Bug #1318991 reported by Andreas Roehler
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

http://stackoverflow.com/questions/23610179/make-ipython-show-source-code-line-where-exception-occurred/23625649#23625649

 IPython show source code line where exception occurred35
up vote36 2 down vote37 favorite38
3

I'm irritated by the following output that IPython gives me for an exception:

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-4c27956d23f6> in <module>()
----> 1 parameterStudyPageRankNibble()

/Users/cls/Desktop/LFR/scripts/scd_experiments.py in parameterStudyPageRankNibble()

AttributeError: 'tuple' object has no attribute 'values'

    A line number from where the exception was raised would be really
    helpful. Why isn't it there?
    /Users/cls/Desktop/LFR/scripts/scd_experiments.py is not the path of the script which is executed. IPython somehow mixed together the path of the script file and the current working directory.

What can I do to get more helpful information when an exception is thrown?

summary: - Make-ipython-show-source-code-line-where-exception-occurred
+ Make IPython show source code line where exception occurred
Changed in python-mode:
importance: Undecided → Medium
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Comment by user unutbu was:

This has to do with how you load the code into IPython. (It would be helpful if you told us how to reproduce your problem.) For example, if I use emacs's M-x py-execute-region, the region of code is copied to a temporary file and the IPython interpreter runs execfile on the temporary file.

When emacs/IPython is used in this manner, there is no useful traceback.

If instead, you import the script and then call the function:

import scd_experiments as SE
SE.parameterStudyPageRankNibble()

then you will see a useful traceback message.

Demo: script.py

def foo():
    1/0

If I select the region and call M-x py-execute-region,

In [15]: ## working on region in file /tmp/python-4126aNj.py...

In [16]: foo()
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-16-624891b0d01a> in <module>()
----> 1 foo()

/tmp/python-4126aNj.py in foo()

ZeroDivisionError: integer division or modulo by zero

;;;;;;;;;

Should not point to /tmp

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Maybe py-execute-region should not use a temporary file by default?

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.2.0
status: New → Confirmed
Revision history for this message
Andreas Roehler (a-roehler) wrote :

fixed with r1499

Changed in python-mode:
status: Confirmed → Fix Committed
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Error still exists with Python3

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:/Users/MYNAME/AppData/Local/Temp/C--Python33-python-3628OHj.py", line 1, in <module>
    1/0
ZeroDivisionError: division by zero
>>>

Changed in python-mode:
status: Fix Committed → In Progress
Changed in python-mode:
status: In Progress → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.