Skip to content

Commit 9aa5b1b

Browse files
rashedmytPrabhakar Kumar
authored andcommitted
Adds exception handling around during tab completion and shutdown sequences of the Kernel.
Fixes #60
1 parent ee66edf commit 9aa5b1b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/jupyter_matlab_kernel/kernel.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class MATLABKernel(ipykernel.kernelbase.Kernel):
213213
}
214214

215215
# MATLAB Kernel state
216+
murl = ""
216217
is_matlab_licensed: bool = False
217218
matlab_status = ""
218219
matlab_proxy_has_error: bool = False
@@ -359,7 +360,9 @@ def do_complete(self, code, cursor_pos):
359360
completion_results = mwi_comm_helpers.send_completion_request_to_matlab(
360361
self.murl, self.headers, code, cursor_pos
361362
)
362-
except HTTPError as e:
363+
except (MATLABConnectionError, HTTPError):
364+
# Jupyter doesn't show the error messages to the user for this request.
365+
# Hence, we'll currently do nothing when an error occurs here.
363366
pass
364367

365368
return {
@@ -399,9 +402,15 @@ def do_history(
399402
)
400403

401404
def do_shutdown(self, restart):
402-
mwi_comm_helpers.send_shutdown_request_to_matlab(
403-
self.murl, self.headers, self.ident
404-
)
405+
try:
406+
mwi_comm_helpers.send_shutdown_request_to_matlab(
407+
self.murl, self.headers, self.ident
408+
)
409+
except (MATLABConnectionError, HTTPError):
410+
# Jupyter doesn't show the error messages to the user for this request.
411+
# Hence, we'll currently do nothing when an error occurs here.
412+
pass
413+
405414
return super().do_shutdown(restart)
406415

407416
# Helper functions

0 commit comments

Comments
 (0)