Skip to content

Commit 7a658a9

Browse files
frenzymadnesspre-commit-ci[bot]hroncok
authored
Improve the error message provided when jupyterhub is missing (jupyterlab#18060)
* Improve the error message provided when jupyterhub is missing Fixes: jupyterlab#18054 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update jupyterlab/labhubapp.py Co-authored-by: Miro Hrončok <[email protected]> * Add a test for the improved error message --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Miro Hrončok <[email protected]>
1 parent c1a8ed1 commit 7a658a9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

jupyterlab/labhubapp.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Distributed under the terms of the Modified BSD License.
55

66
import os
7+
import sys
78

89
from jupyter_server.serverapp import ServerApp
910
from traitlets import default
@@ -18,7 +19,27 @@
1819
from jupyterhub.singleuser.mixins import make_singleuser_app
1920
except ImportError:
2021
# backward-compat with jupyterhub < 1.3
21-
from jupyterhub.singleuser import SingleUserNotebookApp as SingleUserServerApp
22+
try:
23+
from jupyterhub.singleuser import SingleUserNotebookApp as SingleUserServerApp
24+
except ImportError as e:
25+
# jupyterhub is not installed at all
26+
venv_info = sys.prefix
27+
is_venv = sys.base_prefix != sys.prefix
28+
venv_type = "virtual environment" if is_venv else "Python environment"
29+
30+
error_msg = (
31+
f"JupyterHub is not installed and is required to run this application.\n\n"
32+
f"Current {venv_type}: {venv_info}\n\n"
33+
f"Python sys.path entries searched:\n"
34+
)
35+
for path in sys.path:
36+
error_msg += f" - {path}\n"
37+
error_msg += (
38+
f"\nTo fix this issue, install jupyterhub:\n"
39+
f" pip install jupyterhub\n\n"
40+
f"Original error: {e}"
41+
)
42+
raise ImportError(error_msg) from e
2243
else:
2344
SingleUserServerApp = make_singleuser_app(ServerApp)
2445

scripts/ci_script.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ if [[ $GROUP == usage2 ]]; then
364364
rm -f /tmp/jupyter_log_$$.txt
365365

366366
# Check the labhubapp
367+
# Test that the labhubapp fails to start if jupyterhub is not installed
368+
# and provides a helpful error message.
369+
($TEST_INSTALL_PATH/bin/jupyter-labhub 2>&1 || true) | tee labhub.log
370+
grep -q "JupyterHub is not installed" labhub.log || exit 1
371+
# Install jupyterhub and test that the labhubapp starts successfully.
367372
$TEST_INSTALL_PATH/bin/pip install jupyterhub
368373
export JUPYTERHUB_API_TOKEN="mock_token"
369374
$TEST_INSTALL_PATH/bin/jupyter-labhub --HubOAuth.oauth_client_id="mock_id" &

0 commit comments

Comments
 (0)