Skip to content

Commit

Permalink
Merge pull request #23230 from ccordoba12/issue-23124
Browse files Browse the repository at this point in the history
PR: Improve displaying several kernel error messages (IPython console)
  • Loading branch information
ccordoba12 authored Dec 12, 2024
2 parents e4ab11a + 868cbc8 commit 7318cca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
11 changes: 9 additions & 2 deletions spyder/plugins/ipythonconsole/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,12 @@


class SpyderKernelError(RuntimeError):
"""Error to be shown in client."""
pass
"""
Error to be shown in the IPython console.
Notes
-----
* Use this exception if you want to show a nice formatted error in the
current console instead of a long and hard-to-read traceback.
* This should only be used for errors whose cause we are certain of.
"""
7 changes: 4 additions & 3 deletions spyder/plugins/ipythonconsole/utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Local imports
from spyder.api.asyncdispatcher import AsyncDispatcher
from spyder.api.translations import _
from spyder.plugins.ipythonconsole import SpyderKernelError


class KernelClientTunneler:
Expand Down Expand Up @@ -63,10 +64,10 @@ async def forward_port(self, remote_host, remote_port):
)
)
except asyncssh.Error as err:
raise RuntimeError(
raise SpyderKernelError(
_(
"It was not possible to open an SSH tunnel for the "
"remote kernel. Please check your credentials and the "
"It was not possible to open an SSH tunnel to connect to "
"the remote kernel. Please check your credentials and the "
"server connection status."
)
) from err
Expand Down
29 changes: 19 additions & 10 deletions spyder/plugins/ipythonconsole/utils/kernel_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
SPYDER_KERNELS_VERSION,
SPYDER_KERNELS_CONDA,
SPYDER_KERNELS_PIP,
SpyderKernelError,
)
from spyder.plugins.ipythonconsole.comms.kernelcomm import KernelComm
from spyder.plugins.ipythonconsole.utils.manager import SpyderKernelManager
Expand All @@ -35,8 +36,8 @@


PERMISSION_ERROR_MSG = _(
"The directory {} is not writable and it is required to create IPython "
"consoles. Please make it writable."
"The directory <tt>{}</tt> is not writable and it is required to create "
"IPython consoles. Please make it writable."
)

ERROR_SPYDER_KERNEL_VERSION = _(
Expand Down Expand Up @@ -377,7 +378,7 @@ def new_from_spec(cls, kernel_spec):
"""
connection_file = cls.new_connection_file()
if connection_file is None:
raise RuntimeError(
raise SpyderKernelError(
PERMISSION_ERROR_MSG.format(jupyter_runtime_dir())
)

Expand All @@ -390,11 +391,19 @@ def new_from_spec(cls, kernel_spec):

kernel_manager._kernel_spec = kernel_spec

kernel_manager.start_kernel(
stderr=PIPE,
stdout=PIPE,
env=kernel_spec.env,
)
try:
kernel_manager.start_kernel(
stderr=PIPE,
stdout=PIPE,
env=kernel_spec.env,
)
except PermissionError:
# Show a nice error message when jupyter_runtime_dir is not
# writable.
# Fixes spyder-ide/spyder#23124
raise SpyderKernelError(
PERMISSION_ERROR_MSG.format(jupyter_runtime_dir())
)

# Kernel client
kernel_client = kernel_manager.client()
Expand Down Expand Up @@ -474,13 +483,13 @@ def init_kernel_client(
try:
kernel_client.load_connection_file()
except Exception as e:
raise RuntimeError(
raise SpyderKernelError(
_(
"An error occurred while trying to load "
"the kernel connection file. The error "
"was:\n\n"
)
+ str(e)
+ f"<tt>{str(e)}</tt>"
)

if hostname is not None or ssh_connection is not None:
Expand Down

0 comments on commit 7318cca

Please sign in to comment.