line number of error in .sage file

asked 2018-01-30 23:47:45 +0100

ml9nn gravatar image

When sage reports an error, it reports the line number of the .py file where the error occured. I am wondering if there is a way to configure sage so that it instead reports the line number of the code in the .sage file that ultimately generated that problematic line in the .py file.

This would be useful because it is the .sage file that I am actually editing.

This is theoretically possible: other languages and transpilers use sourcemaps to solve this same issue.

edit retag flag offensive close merge delete

Comments

What is a .sage file and what is a .py file?

Does import traceback, followed by traceback.print_exc() at the sensible places, not give the corresponding information?

Where does which sage process report an error? Command line, interpreter?

Example: File content:

# this sage file will deliver a crash at some point...
import traceback

try:
    F = GF(31)
    for a in range(31):
        E = EllipticCurve( F, [a-3,0] )
        print a, E.order()
except Exception:
    traceback.print_exc()

Then

sage: load( '~/asksage/asksage/makemecrash.py' )
0 32
1 32
2 32
Traceback (most recent call last):
  File "/home/dan/asksage/asksage/makemecrash.py", line 7, in <module>
    E = EllipticCurve( F, [a-3,0] )

and so on...

dan_fulea gravatar imagedan_fulea ( 2018-01-31 19:50:17 +0100 )edit

My original file is called file.sage (the ".sage file"). When I execute it via the terminal command sage file.sage, then the file file.sage.py (the ".py file") is automatically generated. I hope this clarifies the issue for you.

ml9nn gravatar imageml9nn ( 2018-02-03 04:47:32 +0100 )edit