Handle error messages through the IOPub error handler or callbacks

Handler methods are only run on a successful request. If an error occurs during
execution an error message is emitted on the IOPub channel, this is where
errors are handled. Or they can be captured in the reply messages through
callbacks.
This commit is contained in:
Nathaniel Nicandro 2018-02-12 10:25:36 -06:00
parent 24eb475443
commit ad0aefe307

View file

@ -853,24 +853,10 @@ the user. Otherwise `read-from-minibuffer' is used."
req
msg)
(jupyter-run-hook-with-args client 'jupyter-shell-message-hook msg)
(let ((content (jupyter-message-content msg)))
;; TODO: How to handle errors? Let the IOPub error message handler deal
;; with it? Or do something here?
(cl-destructuring-bind (&key status _ename _evalue &allow-other-keys) content
(if (member status '("error" "abort"))
;; FIXME: The python kernel will expect errors to be handled by an
;; execute-reply and not emit an error message through IOPub whereas
;; the julia kernel will emit the error both as an IOPub message and
;; in an execute reply.
;;
;; Since there will likely be differences in messaging between
;; kernels, the easiest solution to this would be to allow users to
;; configure the client handling on a much more granular level than
;; just inhibiting the handlers. For example inhibiting only error
;; messages on the iopub channel.
(ignore)
;; (jupyter-handle-error
;; client req ename evalue (plist-get content :traceback))
(let* ((content (jupyter-message-content msg))
(status (jupyter-message-get msg :status)))
;; Let `jupyter-handle-error' handle errors for requests.
(unless (member status '("error" "abort"))
(pcase (jupyter-message-type msg)
("execute_reply"
(cl-destructuring-bind (&key execution_count
@ -926,7 +912,7 @@ the user. Otherwise `read-from-minibuffer' is used."
req protocol_version implementation
implementation_version language_info banner help_links)))
(_
(warn "Message type not handled (%s)" (jupyter-message-type msg))))))))
(warn "Message type not handled (%s)" (jupyter-message-type msg)))))))
(cl-defgeneric jupyter-execute-request ((client jupyter-kernel-client)
&key code