nondescript tracebacks with load and attach

11 views
Skip to first unread message

Marco Streng

unread,
Apr 19, 2011, 10:10:29 AM4/19/11
to sage-...@googlegroups.com
Hi sage-devel,

When debuggin code that is loaded into or attached to a Sage session,
the tracebacks are not very informative: they refer to <string> instead
of to the file name, and give no line numbers or code snippets. This
makes it hard to find out where the error is.

Can this be changed or improved in any way?

Thanks,
Marco

Example:

Suppose I have some files loaded with "load" or "attach", and one of them is
====================
class Bar():
def function_with_common_name(self):
# lots of lines of code
1/0
# lots of lines of code

# other classes that also have functions named function_with_common_name

def foo():
# lots of lines of code
a = Bar()
a.function_with_common_name()
# lots of lines of code
====================

Now I do
====================
sage: foo()
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)

/home/marco/<ipython console> in <module>()

/home/marco/<string> in foo()

/home/marco/<string> in function_with_common_name(self)

/usr/local/sage/sage-4.6.2/local/lib/python2.6/site-packages/sage/structure/element.so
in sage.structure.element.RingElement.__div__
(sage/structure/element.c:11981)()

/usr/local/sage/sage-4.6.2/local/lib/python2.6/site-packages/sage/rings/integer.so
in sage.rings.integer.Integer._div_ (sage/rings/integer.c:11944)()

/usr/local/sage/sage-4.6.2/local/lib/python2.6/site-packages/sage/rings/integer_ring.so
in sage.rings.integer_ring.IntegerRing_class._div
(sage/rings/integer_ring.c:5142)()

ZeroDivisionError: Rational division by zero
====================

Then to find the bug using this traceback, I would need to search my
files to find all functions named "function_with_common_name" that are
called from functions named "foo" for a line that could cause a division
by zero...

Functions that are imported do give useful information, including line
numbers a few lines of code. I'd like to see information like this for
functions that come from loading a file.

Conrado PLG

unread,
May 20, 2011, 10:23:11 AM5/20/11
to sage-devel
On Apr 19, 11:10 am, Marco Streng <marco.str...@gmail.com> wrote:
> Hi sage-devel,
>
> When debuggin code that is loaded into or attached to a Sage session,
> the tracebacks are not very informative: they refer to <string> instead
> of to the file name, and give no line numbers or code snippets. This
> makes it hard to find out where the error is.

I was just going to post the same bug. It used to work, for example,
in Sage 4.3.

Conrado

Simon King

unread,
May 20, 2011, 11:53:57 AM5/20/11
to sage-devel
Hi Marco and Conrado,
I am not sure what is used to create the tracebacks. But I could
imagine that it uses stuff from sage.misc.sageinspect or
sage.misc.edit_module.

If this is the case, then it could help to use the patches from #9976
(merged in sage-4.7.1.alpha0) and #11298. Both patches greatly improve
the functionality of introspection (e.g., you can inspect
interactively defined Cython code). I will test whether they help with
your tracebacks.

And #11298 needs review, btw.

Cheers,
Simon

Simon King

unread,
May 20, 2011, 12:03:43 PM5/20/11
to sage-devel
Yep, it works!

On 20 Mai, 17:53, Simon King <simon.k...@uni-jena.de> wrote:
> If this is the case, then it could help to use the patches from #9976
> (merged in sage-4.7.1.alpha0) and #11298. Both patches greatly improve
> the functionality of introspection (e.g., you can inspect
> interactively defined Cython code). I will test whether they help with
> your tracebacks.

I've put your code into a file bla.py, and attached it to a Sage
session.

With the patches from #9976, I got

sage: attach "bla.py"
sage: foo()
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call
last)

/home/king/SAGE/tests/<ipython console> in <module>()

/home/king/SAGE/tests/bla.py in foo()
9 def foo():
10 # lots of lines of code
11 a = Bar()
---> 12 a.function_with_common_name()
13 # lots of lines of code

/home/king/SAGE/tests/bla.py in function_with_common_name(self)
2 def function_with_common_name(self):
3 # lots of lines of code
----> 4 1/0
5 # lots of lines of code
6

ZeroDivisionError: integer division or modulo by zero


In other words, the problem will be fixed in sage-4.7.1, and #11298 is
not needed for that example.

But:
> And #11298 needs review, btw.

Please... :)

Cheers,
Simon

Simon King

unread,
May 21, 2011, 1:40:58 AM5/21/11
to sage-devel
Hi Marco,

could you please provide more information about your system?

Namely, originally I had only tested that your example works fine if I
use sage-4.7.rc2 plus trac ticket #9976. But now, I tested again with
plain unpatched sage-4.6.2 -- and it STILL works.

On 19 Apr., 16:10, Marco Streng <marco.str...@gmail.com> wrote:
> /usr/local/sage/sage-4.6.2/local/lib/python2.6/site-packages/sage/structure/element.so
> in sage.structure.element.RingElement.__div__
> (sage/structure/element.c:11981)()

So, apparently you used sage-4.6.2 as well. But then, I wonder why I
can't reproduce the problem.

Best regards,
Simon

Willem Jan Palenstijn

unread,
May 21, 2011, 10:23:01 AM5/21/11
to sage-...@googlegroups.com
On Fri, May 20, 2011 at 10:40:58PM -0700, Simon King wrote:
> Hi Marco,
>
> could you please provide more information about your system?
>
> Namely, originally I had only tested that your example works fine if I
> use sage-4.7.rc2 plus trac ticket #9976. But now, I tested again with
> plain unpatched sage-4.6.2 -- and it STILL works.

There's a difference between loading (or attaching) .py files and .sage files.
Maybe that is what's different?

-Willem Jan

Reply all
Reply to author
Forward
0 new messages