3

I have a python code block in an org-file that when executed results in some error. I was expecting to see that error in the #+RESULTS: block, but it doesn't show up. I have to navigate to the python session buffer in order to see whether the evaluation was successful. More over, when a previous code block is unsuccessful, and the next code block depends on it's results, I can continue executing code without any indications that evaluation is failing (except for missing output).

How can I configure org-babel to display such errors/exceptions in the #+RESULTS: block?

How to reproduce

I have this property set at the top of my org file

#+PROPERTY: header-args :session my_py_session

Sample block

#+BEGIN_SRC python
r = some_function_which_results_in_a_trace_back()
#+END_SRC

#+BEGIN_SRC python
x = r*2
#+END_SRC

When I do a C-c on both these blocks, Emacs reports something like Code block evaluation complete (took 0.5 secs) in the mini buffer.

But when I open the python session buffer, I see this error. How can I get this error to show in the #+RESULTS: block?

>>> 
org_babel_python_eoe
Traceback (most recent call last):
  File "<string>", line 17, in __PYTHON_EL_eval
  File "/var/folders/7k/r1g1zhmx16gbtm1hbllhhk_w0000gs/T/py3Fvne8", line 18, in <module>
  File "<string>", line 4, in <module>
  File "<string>", line 2, in <module>
NameError: name 'some_function_which_results_in_a_trace_back' is not defined. Did you mean: 'NameError'?
>>> 
org_babel_python_eoe
Traceback (most recent call last):
  File "<string>", line 17, in __PYTHON_EL_eval
  File "/var/folders/7k/r1g1zhmx16gbtm1hbllhhk_w0000gs/T/pywWfEwY", line 8, in <module>
  File "<string>", line 1, in <module>
NameError: name 'r' is not defined

What I already tried

#+BEGIN_SRC python :results output
try:
    r = some_error()
except Exception as e:
    print(e)
#+END_SRC

#+RESULTS:
: name 'some_error' is not defined
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.