Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(bootstrap): fail fast when nvm cannot activate the pinned node

mateo-berrie528e57e53ad
diff --git a/scripts/with_dashboard_node.sh b/scripts/with_dashboard_node.sh
index dd2f36774a6..01643837413 100755
--- a/scripts/with_dashboard_node.sh
+++ b/scripts/with_dashboard_node.sh
@@ -28,9 +28,9 @@ nvm_script="${NVM_DIR:-$HOME/.nvm}/nvm.sh"
if [ -r "$nvm_script" ]; then
echo "with_dashboard_node: node ${current:-missing} is below the dashboard floor $floor; switching to $pinned via nvm" >&2
set +eu
- . "$nvm_script" --no-use
- nvm install "$pinned" >&2
- nvm use "$pinned" >&2
+ . "$nvm_script" --no-use || { echo "with_dashboard_node: could not load nvm from $nvm_script" >&2; exit 1; }
+ nvm install "$pinned" >&2 || { echo "with_dashboard_node: nvm install $pinned failed" >&2; exit 1; }
+ nvm use "$pinned" >&2 || { echo "with_dashboard_node: nvm use $pinned failed" >&2; exit 1; }
set -eu
exec "$@"
fi
diff --git a/tests/test_litellm/test_with_dashboard_node.py b/tests/test_litellm/test_with_dashboard_node.py
index 0d505983f16..c0e83ac24b2 100644
--- a/tests/test_litellm/test_with_dashboard_node.py
+++ b/tests/test_litellm/test_with_dashboard_node.py
@@ -95,6 +95,38 @@ def test_old_node_switches_via_fnm_when_nvm_is_absent(tmp_path):
assert "via fnm" in proc.stderr
+def _nvm_home(tmp_path, nvm_sh: str) -> Path:
+ home = tmp_path / "home"
+ nvm_dir = home / ".nvm"
+ nvm_dir.mkdir(parents=True)
+ (nvm_dir / "nvm.sh").write_text(nvm_sh)
+ return home
+
+
+def test_failing_nvm_load_stops_before_running_the_command(tmp_path):
+ old = _fake_node(tmp_path / "old-bin", _bump_major(_floor(), -1))
+ proc = _run([old], _nvm_home(tmp_path, "false\n"))
+ assert proc.returncode == 1
+ assert "could not load nvm" in proc.stderr
+ assert proc.stdout == ""
+
+
+def test_failing_nvm_install_stops_before_running_the_command(tmp_path):
+ old = _fake_node(tmp_path / "old-bin", _bump_major(_floor(), -1))
+ proc = _run([old], _nvm_home(tmp_path, 'nvm() { [ "$1" = install ] && return 1; return 0; }\n'))
+ assert proc.returncode == 1
+ assert "nvm install" in proc.stderr
+ assert proc.stdout == ""
+
+
+def test_failing_nvm_use_stops_before_running_the_command(tmp_path):
+ old = _fake_node(tmp_path / "old-bin", _bump_major(_floor(), -1))
+ proc = _run([old], _nvm_home(tmp_path, 'nvm() { [ "$1" = use ] && return 1; return 0; }\n'))
+ assert proc.returncode == 1
+ assert "nvm use" in proc.stderr
+ assert proc.stdout == ""
+
+
def test_no_command_is_a_usage_error(tmp_path):
proc = subprocess.run(
[str(SCRIPT)],