Opened 16 years ago

Last modified 8 years ago

#71 new enhancement

Better tracebacks

Reported by: Justin Walker (justin@… Owned by: Carl Witty
Priority: minor Milestone: sage-6.5
Component: misc Keywords:
Cc: Merged in:
Authors: Jeroen Demeyer Reviewers:
Report Upstream: N/A Work issues:
Branch: u/jdemeyer/ticket/71 (Commits, GitHub, GitLab) Commit: f3033437293a2f7c0beedc6884847a18ddba63f8
Dependencies: #17382 Stopgaps:

Status badges

Description (last modified by Jeroen Demeyer)

When a .sage file is "load"ed or "attach"ed, it gets translated to a .py file before being processed; the result is a file with different structure than the original. Any errors are described in terms of the .py file, not the .sage file.

One working solution is to monkey-patch traceback.extract_tb() to undo preparsing.

The traceback below was generated with this patch. It shows the unpreparsed 1/0 and it also shows the Cython source (see #17382):

sage: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-1-3cdd7c9e2324> in <module>()
----> 1 1/0

/usr/local/src/sage-config/sage/structure/element.pyx in sage.structure.element.RingElement.__div__ (build/cythonized/sage/structure/element.c:17829)()
   1891                 return (<RingElement>self)._idiv_(<RingElement>right)
   1892             else:
-> 1893                 return (<RingElement>self)._div_(<RingElement>right)
   1894         global coercion_model
   1895         return coercion_model.bin_op(self, right, div)

/usr/local/src/sage-config/sage/rings/integer.pyx in sage.rings.integer.Integer._div_ (build/cythonized/sage/rings/integer.c:12964)()
   1795         # This is vastly faster than doing it here, since here
   1796         # we can't cimport rationals.
-> 1797         return the_integer_ring._div(self, right)
   1798 
   1799     def __floordiv__(x, y):

/usr/local/src/sage-config/sage/rings/integer_ring.pyx in sage.rings.integer_ring.IntegerRing_class._div (build/cythonized/sage/rings/integer_ring.c:4578)()
    443         cdef rational.Rational x = PY_NEW(rational.Rational)
    444         if mpz_sgn(right.value) == 0:
--> 445             raise ZeroDivisionError, 'Rational division by zero'
    446         mpz_set(mpq_numref(x.value), left.value)
    447         mpz_set(mpq_denref(x.value), right.value)

ZeroDivisionError: Rational division by zero

Change History (20)

comment:1 Changed 16 years ago by William Stein

SAGE can embed the original line numbers in the .py file, and even the original .sage lines (before parsing) in the .sage file. Then the error messages will also list the original line number (and line, if you want) in a comment at the end of the line. In the notebook, at least, it would be easy to postparse the error messages so they refer to the original .sage file.

comment:2 Changed 16 years ago by William Stein

Type: defectenhancement

This is not a bug.

comment:3 Changed 15 years ago by Michael Abshoff

Milestone: sage-feature

comment:4 Changed 13 years ago by David Loeffler

Component: basic arithmeticmisc
Owner: changed from somebody to Carl Witty

comment:5 Changed 13 years ago by Alex Ghitza

Summary: Secret transation of .sage to .py causes confusionSecret translation of .sage to .py causes confusion

comment:6 Changed 10 years ago by Karl-Dieter Crisman

Report Upstream: N/A

Hi. This is a REALLY old ticket. Is the documentation at the programming tutorial now sufficient, or should we still keep this ticket around? I love the idea in William's (six-year-old) comment:1, so we could repurpose this ticket to implement this if desired. Or, one could just improve the documentation a little to mention that errors refer to lines in the .py file.

comment:7 Changed 8 years ago by Jeroen Demeyer

Description: modified (diff)

comment:8 Changed 8 years ago by Jeroen Demeyer

Description: modified (diff)

comment:9 Changed 8 years ago by Jeroen Demeyer

Summary: Secret translation of .sage to .py causes confusionPreparsing causes confusing error messages

comment:10 Changed 8 years ago by Jeroen Demeyer

Authors: Jeroen Demeyer
Description: modified (diff)

comment:11 Changed 8 years ago by Jeroen Demeyer

Description: modified (diff)
Milestone: sage-featuresage-6.5

comment:12 Changed 8 years ago by Jeroen Demeyer

Summary: Preparsing causes confusing error messagesBetter tracebacks

comment:13 Changed 8 years ago by Jeroen Demeyer

Branch: u/jdemeyer/ticket/71
Modified: Nov 20, 2014, 4:39:07 PMNov 20, 2014, 4:39:07 PM

comment:14 Changed 8 years ago by git

Commit: 151b6fa3bbecf2ed4914bd65454be620d47fed9a

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

151b6faTrac #71: Better tracebacks: unpreparse and fix Cython files

comment:15 Changed 8 years ago by Jeroen Demeyer

Description: modified (diff)
Report Upstream: N/ANot yet reported upstream; Will do shortly.

comment:16 Changed 8 years ago by git

Commit: 151b6fa3bbecf2ed4914bd65454be620d47fed9a51eb4400e9ffd3ab79971b402af546828737f6f3

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

51eb440Trac #71: Better tracebacks: unpreparse and show Cython files

comment:17 Changed 8 years ago by git

Commit: 51eb4400e9ffd3ab79971b402af546828737f6f30355c6d309f490160299ef0722605200b406f8c9

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

0355c6dTrac #71: Better tracebacks: unpreparse and show Cython files

comment:18 Changed 8 years ago by git

Commit: 0355c6d309f490160299ef0722605200b406f8c999003530ae42e5ddbc96d1516d3f27a779bdfecb

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

9900353Trac #71: Better tracebacks: unpreparse and show Cython files

comment:19 Changed 8 years ago by Jeroen Demeyer

Dependencies: #17382
Description: modified (diff)
Report Upstream: Not yet reported upstream; Will do shortly.N/A

comment:20 Changed 8 years ago by git

Commit: 99003530ae42e5ddbc96d1516d3f27a779bdfecbf3033437293a2f7c0beedc6884847a18ddba63f8

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

02d5d23Show Cython code in IPython tracebacks
f303343Trac #71: unpreparse in tracebacks
Note: See TracTickets for help on using tickets.