Open rhymer opened 8 years ago
That would be awesome.
Hi, we, @tlentali and I, would like to help.
If I understand, you want to have a clickable line to your org file, inside the source block, when a traceback occurs?
Is it easy to identify the source block BEGIN_SRC
in the file? I think it's possible to parse the lineno from the traceback. If you know the source block which posts the snippet of code, you can get the right line.
Thank you. Cheers, Damien
There are two possible cases:
Error occurs in another file. This one is easier, because the traceback tells you something like
NameError Traceback (most recent call last)
in () 17 from importlib import reload 18 reload(scenario_parser) ---> 19 scenario_parser.wrong_fun() /prj/mytools/scenario_parser.py in wrong_fun() 577 578 def wrong_fun(): --> 579 return x 580 581 if **name** == "**main**": NameError: name 'x' is not defined
Error occurs in some org source block: This is trickier because each org source block is translated to some temporary file/buffer. It's not clear to me how to find the line number of the corresponding org source block. Example:
NameError Traceback (most recent call last)
in () 12 a = string_to_array("5.5") 13 a ---> 14 wrong_fun() in wrong_fun() 1 def wrong_fun(): ----> 2 return x NameError: name 'x' is not defined
Like you've pointed out, if we know which source block contains the error, it should be easy to get to the right line. The hard part is knowing what ipython-input-12-a4e4c76b432d corresponds to. Any idea?
You can get the lines of a src block using something like (assuming point
is somewhere inside the src-block
)
(let* ((src-block (org-element-at-point))
(src (org-element-property :value src-block))
(split-string src))
See the org-element API for more info.
With regards to figuring out how to know which source block the error occurs in, we can use the org-babel-current-src-block-location
marker since it is set before the call to org-babel-execute:ipython
. We can copy this marker and pass it along to ob-ipython--eval
to have the source block location available when an error happens.
Is it possible to make error traceback clickable and brings you to the line where error occurs? Thanks.