Skip to content
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

Document the handling of error in do_execute #500

Merged
merged 1 commit into from
Feb 4, 2020
Merged

Conversation

BoPeng
Copy link
Contributor

@BoPeng BoPeng commented Dec 23, 2019

My customized kernel does something like the following to handle errors

    def _do_execute(self,
                    code,
                    silent,
                    store_history=True,
                    user_expressions=None,
                    allow_stdin=True):
        try:
            # do stuff
        except Exception as e:
            return {
                'status': 'error',
                'ename': e.__class__.__name__,
                'evalue': str(e),
                'traceback': [],
                'execution_count': self._execution_count,
            }

which works fine during interactive data analysis or through Run all cells. However, papermill does not recognizes the error and returns 0 when it converts notebooks with my kernel. It turns out that a message of type error should be sent through self.send_response in addition to returning execute_reply with status of error. Although I believe the caller of this do_execute function should automatically do this, this PR documents the proper way of handling errors in this function, namely

    def _do_execute(self,
                    code,
                    silent,
                    store_history=True,
                    user_expressions=None,
                    allow_stdin=True):
        try:
            # do stuff
        except Exception as e:
            msg = {
                'status': 'error',
                'ename': e.__class__.__name__,
                'evalue': str(e),
                'traceback': [],
                'execution_count': self._execution_count,
            }
            self.send_response(self.iopub_channel, 'error', msg)
            return msg

@jasongrout
Copy link
Member

I agree that it would be convenient if the caller of this method sent the execute_results iopub message, as documented in https://jupyter-client.readthedocs.io/en/stable/messaging.html#id6

@BoPeng
Copy link
Contributor Author

BoPeng commented Dec 23, 2019

This is the relevant papermill dicussion nteract/papermill#337

@minrk minrk merged commit c1b85ea into jupyter:master Feb 4, 2020
@meeseeksmachine
Copy link

This pull request has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/jupyter-client-6-0-0/3414/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants