-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print useful error message on exception #142
Conversation
Sometimes apparently the 'traceback' can be None, which results in throwing a `TypeError` exception. With this fix the actual underlying error will get printed, so that users can fix it. Fixes jupyter#141.
With this PR, I now get the following output: (xeuslf) lfortran/lfortran(ast1) $ jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=60 --output Demo1_out.ipynb share/lfortran/nb/Demo1.ipynb
[NbConvertApp] Converting notebook share/lfortran/nb/Demo1.ipynb to notebook
Run with XEUS 1.0.1
[NbConvertApp] Executing notebook with kernel: fortran
Traceback (most recent call last):
File "/Users/certik/miniforge3/envs/xeuslf/bin/jupyter-nbconvert", line 11, in <module>
sys.exit(main())
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/jupyter_core/application.py", line 254, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/traitlets/config/application.py", line 845, in launch_instance
app.start()
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 350, in start
self.convert_notebooks()
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 524, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 489, in convert_single_notebook
output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 418, in export_single_notebook
output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 181, in from_filename
return self.from_file(f, resources=resources, **kw)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 199, in from_file
return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/exporters/notebook.py", line 32, in from_notebook_node
nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 143, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 318, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/preprocessors/base.py", line 47, in __call__
return self.preprocess(nb, resources)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 79, in preprocess
self.execute()
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/util.py", line 74, in wrapped
return just_run(coro(*args, **kwargs))
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/util.py", line 53, in just_run
return loop.run_until_complete(coro)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/client.py", line 553, in async_execute
await self.async_execute_cell(
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 123, in async_execute_cell
cell, resources = self.preprocess_cell(cell, self.resources, cell_index)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 146, in preprocess_cell
cell = run_sync(NotebookClient.async_execute_cell)(self, cell, index, store_history=self.store_history)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/util.py", line 74, in wrapped
return just_run(coro(*args, **kwargs))
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/util.py", line 53, in just_run
return loop.run_until_complete(coro)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nest_asyncio.py", line 70, in run_until_complete
return f.result()
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/asyncio/futures.py", line 201, in result
raise self._exception
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/asyncio/tasks.py", line 256, in __step
result = coro.send(None)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/client.py", line 857, in async_execute_cell
self._check_raise_for_error(cell, exec_reply)
File "/Users/certik/miniforge3/envs/xeuslf/lib/python3.9/site-packages/nbclient/client.py", line 760, in _check_raise_for_error
raise CellExecutionError.from_cell_and_msg(cell, exec_reply_content)
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
integer :: i
do i = 1, 4
if (i == 3) cycle
print *, "variable i =", i
end do
------------------
CompilerError: input:1:1 semantic error: Symbol already declared
^~~~~~~~~~~~~ Which is an error coming from our LFortran Jupyter kernel, and that is our problem to fix. But at least we know what the problem is, which before was hard to figure out. |
I suppose you are using a xeus-based kernel, @JohanMabille do you know why we would have an error without a traceback? |
Co-authored-by: David Brochart <[email protected]>
Yes, we use the xeus based kernel. Great suggestion to simplify the code, I was thinking there is some one liner, but couldn't think of any. :) |
Thanks @certik! |
Returning the traceback in the reply message must be implemented in the kernel itself since it is specific to the interpreter / compiler used. |
Would it make sense to have an empty list by default in xeus? |
@certik do you need an nbclient release soon? |
Here is where we (currently) return an empty traceback: result["traceback"] = {}; What should we do instead? @davidbrochart, no I don't need a release soon. I can fix our bug locally and then everything works. I just submitted this PR for the future once we hit another error. |
Shouldn't it be an empty array? result["traceback"] = json::array(); |
Thanks for the suggestion. I actually don't know. @JohanMabille, is that the case? |
Indeed, the traceback is supposed to be an array when the status is 'error'. You can find more detail in the protocol documentation. |
I actually wonder if we should provide functions for building the messages in xeus, with the expected arguments (and their types), when the reply has to be built in the kernel itself. This would help kernel authors to focus on the interpreter / language features without having to check how to "finish" to implement the protocol. |
Thanks, I'll change it to an array. Yes, that would be really helpful to provide more helper routines --- I really struggled to "finish" the protocol, and as you can see, even got it wrong. |
I tested using the |
Sometimes apparently the 'traceback' can be None, which results in throwing a
TypeError
exception.With this fix the actual underlying error will get printed, so that users can fix it.
Fixes #141.