Opened 16 years ago
Last modified 8 years ago
#71 new enhancement
Better tracebacks
Reported by:  Owned by:  Carl Witty  

Priority:  minor  Milestone:  sage6.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: 
Description (last modified by )
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 monkeypatch 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) <ipythoninput13cdd7c9e2324> in <module>() > 1 1/0 /usr/local/src/sageconfig/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/sageconfig/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/sageconfig/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
comment:3 Changed 15 years ago by
Milestone:  → sagefeature 

comment:4 Changed 13 years ago by
Component:  basic arithmetic → misc 

Owner:  changed from somebody to Carl Witty 
comment:5 Changed 13 years ago by
Summary:  Secret transation of .sage to .py causes confusion → Secret translation of .sage to .py causes confusion 

comment:6 Changed 10 years ago by
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 (sixyearold) 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
Description:  modified (diff) 

comment:8 Changed 8 years ago by
Description:  modified (diff) 

comment:9 Changed 8 years ago by
Summary:  Secret translation of .sage to .py causes confusion → Preparsing causes confusing error messages 

comment:10 Changed 8 years ago by
Authors:  → Jeroen Demeyer 

Description:  modified (diff) 
comment:11 Changed 8 years ago by
Description:  modified (diff) 

Milestone:  sagefeature → sage6.5 
comment:12 Changed 8 years ago by
Summary:  Preparsing causes confusing error messages → Better tracebacks 

comment:13 Changed 8 years ago by
Branch:  → u/jdemeyer/ticket/71 

Modified:  Nov 20, 2014, 4:39:07 PM → Nov 20, 2014, 4:39:07 PM 
comment:14 Changed 8 years ago by
Commit:  → 151b6fa3bbecf2ed4914bd65454be620d47fed9a 

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
151b6fa  Trac #71: Better tracebacks: unpreparse and fix Cython files

comment:15 Changed 8 years ago by
Description:  modified (diff) 

Report Upstream:  N/A → Not yet reported upstream; Will do shortly. 
comment:16 Changed 8 years ago by
Commit:  151b6fa3bbecf2ed4914bd65454be620d47fed9a → 51eb4400e9ffd3ab79971b402af546828737f6f3 

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
51eb440  Trac #71: Better tracebacks: unpreparse and show Cython files

comment:17 Changed 8 years ago by
Commit:  51eb4400e9ffd3ab79971b402af546828737f6f3 → 0355c6d309f490160299ef0722605200b406f8c9 

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
0355c6d  Trac #71: Better tracebacks: unpreparse and show Cython files

comment:18 Changed 8 years ago by
Commit:  0355c6d309f490160299ef0722605200b406f8c9 → 99003530ae42e5ddbc96d1516d3f27a779bdfecb 

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
9900353  Trac #71: Better tracebacks: unpreparse and show Cython files

comment:19 Changed 8 years ago by
Dependencies:  → #17382 

Description:  modified (diff) 
Report Upstream:  Not yet reported upstream; Will do shortly. → N/A 
comment:20 Changed 8 years ago by
Commit:  99003530ae42e5ddbc96d1516d3f27a779bdfecb → f3033437293a2f7c0beedc6884847a18ddba63f8 

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.