Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Tell npm permission and firewall failures apart from a blocked registry (#8729)

Sergio Romerod9a715c86c4f
diff --git a/studio/setup.ps1 b/studio/setup.ps1
index 200289f1e2a..04322f37f02 100644
--- a/studio/setup.ps1
+++ b/studio/setup.ps1
@@ -3097,6 +3097,28 @@ function substep {
}
}
+# Matched on npm's error code line, not anywhere in the log: Windows cleanup warnings
+# carry EPERM after a network failure too. FetchError names registry.npmjs.org even
+# on a local errno, so this runs before the network check (#8725).
+$script:NpmLocalFailureRe = 'npm (error|ERR!) code (EACCES|EPERM|EBUSY|ENOSPC|ENFILE|EMFILE)|operation was rejected by your operating system'
+# Keep in sync with _suggest_npm_registry in studio/setup.sh.
+$script:NpmNetworkFailureRe = '40[13]|ENOTFOUND|ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ConnectionRefused|failed to resolve|registry\.npmjs\.org|getaddrinfo|tunneling socket|network|proxy|self.?signed|unable to (get|verify)'
+
+function Show-NpmLocalFailureHint {
+ # -Socket: FetchError with no "npm error path" line, i.e. the OS refused node.exe's
+ # socket (per-program firewall / antivirus rule). A cache write failure has a path.
+ param([switch]$Socket)
+ Write-StudioLine ""
+ if ($Socket) {
+ $nodePath = try { (Get-Command node -ErrorAction Stop).Source } catch { "node.exe" }
+ step "frontend" "the OS refused node's connection to the npm registry" "Yellow"
+ substep "Allow $nodePath in your firewall/antivirus, or use another Node install."
+ return
+ }
+ step "frontend" "npm hit a local file error (permission, lock or disk full)" "Yellow"
+ substep "Try: npm cache clean --force, or exclude the npm cache from your antivirus."
+}
+
function Invoke-NpmMirrorRetry {
if (-not $env:_UNSLOTH_MIRROR_SPARE) { return $false }
if ((Get-MirrorFailedHost -Output $script:SetupCommandOutput -Ran npm) -ne 'npm') { return $false }
@@ -3111,6 +3133,13 @@ function Invoke-NpmMirrorRetry {
}
function Show-NpmRegistryHint {
+ # Empty output (verbose runs stream npm) keeps the unconditional registry hint.
+ param([string]$FailureOutput = "")
+ if ($FailureOutput) {
+ $FailureOutput = $FailureOutput -replace "$([char]27)\[[0-9;]*m", ''
+ if ($FailureOutput -cmatch $script:NpmLocalFailureRe) { Show-NpmLocalFailureHint -Socket:($FailureOutput -cmatch 'FetchError' -and $FailureOutput -cnotmatch 'npm (error|ERR!) path '); return }
+ if ($FailureOutput -inotmatch $script:NpmNetworkFailureRe) { return }
+ }
if ($env:UNSLOTH_NPM_REGISTRY) { return }
$mirror = $env:NPM_CONFIG_REGISTRY
if (-not $mirror) {
@@ -5834,7 +5863,7 @@ if ($NeedFrontendBuild -and -not $IsPipInstall) {
foreach ($gi in $HiddenGitignores) { Rename-Item -Path "$gi._twbuild" -NewName (Split-Path $gi -Leaf) -Force -ErrorAction SilentlyContinue }
Write-StudioLine "[ERROR] npm $NpmInstallVerb failed (exit code $npmExit)" -ForegroundColor Red
Write-StudioLine " Try running 'npm $NpmInstallVerb' manually in frontend/ to see errors" -ForegroundColor Yellow
- Show-NpmRegistryHint
+ Show-NpmRegistryHint -FailureOutput $script:SetupCommandOutput
Exit-SetupFailure "Frontend dependency installation failed (exit code $npmExit)"
}
}
@@ -5877,7 +5906,7 @@ if ((Test-Path $OxcValidatorDir) -and $NodeSource -ne "skip" -and (Get-Command n
Pop-Location
$ErrorActionPreference = $prevEAP_oxc
Write-StudioLine "[ERROR] OXC validator npm $NpmInstallVerb failed (exit code $oxcInstallExit)" -ForegroundColor Red
- Show-NpmRegistryHint
+ Show-NpmRegistryHint -FailureOutput $script:SetupCommandOutput
Exit-SetupFailure "OXC validator dependency installation failed (exit code $oxcInstallExit)"
}
Pop-Location
diff --git a/studio/setup.sh b/studio/setup.sh
index 028b389d821..d86f659a281 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -573,13 +573,44 @@ _npm_mirror_retry() {
_NPM_REGISTRY_ARGS=(--registry "$UNSLOTH_NPM_REGISTRY")
}
+# Local errno is matched on npm's code line only (cleanup warnings carry EPERM after
+# network failures too) and before the network check, since FetchError names
+# registry.npmjs.org even on a local error (#8725). Keep in sync with setup.ps1.
+_NPM_LOCAL_FAILURE_RE='npm (error|ERR!) code (EACCES|EPERM|EBUSY|ENOSPC|ENFILE|EMFILE)|operation was rejected by your operating system'
+
+# $1 = "socket": FetchError with no "npm error path" line, i.e. the OS refused node's
+# socket (per-program firewall / antivirus rule). A cache write failure has a path.
+_suggest_npm_local_failure() {
+ printf '\n' >&2
+ if [ "${1:-}" = socket ]; then
+ step "frontend" "the OS refused node's connection to the npm registry" "$C_WARN" >&2
+ substep "Allow $(command -v node 2>/dev/null || echo node) in your firewall/antivirus, or use another Node install." >&2
+ return 0
+ fi
+ step "frontend" "npm hit a local file error (permission, lock or disk full)" "$C_WARN" >&2
+ substep "Try: npm cache clean --force, or check the npm cache is writable." >&2
+ return 0
+}
+
# Print actionable guidance when a frontend/OXC npm/bun install fails and the registry
# lock is the likely cause (corporate firewall/proxy). No-op once the user has opted in
# via UNSLOTH_NPM_REGISTRY. This only guides; the mirror fallback does any switching.
# $1 = path to a captured install log (may be empty/missing).
_suggest_npm_registry() {
- [ -n "${UNSLOTH_NPM_REGISTRY:-}" ] && return 0
local _log="${1:-}"
+ # Before the UNSLOTH_NPM_REGISTRY opt-out: a mirror does not unlock a cache.
+ local _plain=""
+ # Strip ANSI colour (npm color=always) so the code-line match still sees "npm error code".
+ if [ -n "$_log" ] && [ -s "$_log" ]; then _plain="$(sed "s/$(printf '\033')\[[0-9;]*m//g" "$_log")"; fi
+ if [ -n "$_plain" ] && grep -Eq "$_NPM_LOCAL_FAILURE_RE" <<<"$_plain"; then
+ if grep -q 'FetchError' <<<"$_plain" && ! grep -Eq 'npm (error|ERR!) path ' <<<"$_plain"; then
+ _suggest_npm_local_failure socket
+ else
+ _suggest_npm_local_failure
+ fi
+ return 0
+ fi
+ [ -n "${UNSLOTH_NPM_REGISTRY:-}" ] && return 0
# If we captured output and it does NOT look like a registry/network problem, stay
# quiet -- the raw error already shown is more useful than a misleading hint.
if [ -n "$_log" ] && [ -s "$_log" ] \
diff --git a/tests/sh/test_npm_failure_hint.sh b/tests/sh/test_npm_failure_hint.sh
new file mode 100755
index 00000000000..f20123f4624
--- /dev/null
+++ b/tests/sh/test_npm_failure_hint.sh
@@ -0,0 +1,104 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+# See /studio/LICENSE.AGPL-3.0
+#
+# _suggest_npm_registry in studio/setup.sh: a local npm errno gets a local hint, not
+# "registry.npmjs.org looks blocked". #8725's EACCES came from the HTTP socket
+# (FetchError), so it gets the "OS refused node's connection" variant.
+
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+SETUP_SH="$SCRIPT_DIR/../../studio/setup.sh"
+PASS=0
+FAIL=0
+
+_FUNC_FILE=$(mktemp)
+_log_file=$(mktemp)
+trap 'rm -f "$_FUNC_FILE" "$_log_file"' EXIT
+{
+ sed -n '/^_NPM_LOCAL_FAILURE_RE=/p' "$SETUP_SH"
+ sed -n '/^_suggest_npm_local_failure()/,/^}/p' "$SETUP_SH"
+ sed -n '/^_suggest_npm_registry()/,/^}/p' "$SETUP_SH"
+} > "$_FUNC_FILE"
+for _needle in '_NPM_LOCAL_FAILURE_RE=' '_suggest_npm_local_failure()' '_suggest_npm_registry()'; do
+ grep -q -- "$_needle" "$_FUNC_FILE" || { echo "FAIL: could not extract $_needle from $SETUP_SH"; exit 1; }
+done
+
+step() { printf ' %-15s%s\n' "$1" "$2" >&2; }
+substep() { printf ' %-15s%s\n' "" "$1" >&2; }
+C_WARN=""
+# shellcheck disable=SC1090
+. "$_FUNC_FILE"
+
+_EACCES_LOG="npm error code EACCES
+npm error FetchError: request to https://registry.npmjs.org/oxlint/-/oxlint-1.65.0.tgz failed, reason:
+npm error The operation was rejected by your operating system."
+
+_EPERM_LOG="npm ERR! code EPERM
+npm ERR! syscall rename
+npm ERR! Error: EPERM: operation not permitted, rename 'C:\\npm-cache\\_cacache\\tmp\\x'"
+
+# Real npm 10.9 output for a cache dir with a deny-write ACL: FetchError, but with a path.
+_CACHE_ACL_LOG="npm error code EPERM
+npm error syscall mkdir
+npm error path D:\\a\\_temp\\x\\cache\\_cacache
+npm error errno EPERM
+npm error FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/is-number: EPERM: operation not permitted, mkdir 'D:\\a\\_temp\\x\\cache\\_cacache'"
+
+_ESC=$(printf '\033')
+_COLOR_EPERM_LOG="${_ESC}[31mnpm${_ESC}[39m ${_ESC}[31merror${_ESC}[39m ${_ESC}[90mcode${_ESC}[39m EPERM
+${_ESC}[31mnpm${_ESC}[39m ${_ESC}[31merror${_ESC}[39m syscall rename"
+
+_NETWORK_LOG="npm error code ENOTFOUND
+npm error network request to https://registry.npmjs.org/oxlint failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org"
+
+# Windows npm warns about EPERM during cleanup after a genuine network failure.
+_NETWORK_CLEANUP_LOG="npm warn cleanup Failed to remove some directories [
+npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\\x\\node_modules\\oxlint']
+npm warn cleanup ]
+npm error code ETIMEDOUT
+npm error network request to https://registry.npmjs.org/oxlint failed"
+
+_PROXY_LOG="npm error code E403
+npm error 403 Forbidden - GET https://registry.npmjs.org/oxlint"
+
+_UNRELATED_LOG="npm error code ELIFECYCLE
+npm error [email protected] postinstall script failed"
+
+# check <name> <log> <expected hint: file|socket|registry|none>
+check() {
+ printf '%s\n' "$2" > "$_log_file"
+ [ -n "$2" ] || : > "$_log_file"
+ local _out _got=""
+ _out="$( _suggest_npm_registry "$_log_file" 2>&1 )"
+ case "$_out" in *"local file error"*) _got="$_got file" ;; esac
+ case "$_out" in *"refused node's connection"*) _got="$_got socket" ;; esac
+ case "$_out" in *"looks blocked (corporate firewall/proxy?)"*) _got="$_got registry" ;; esac
+ _got="${_got# }"
+ if [ "${_got:-none}" = "$3" ]; then
+ PASS=$((PASS + 1)); echo "ok $1"
+ else
+ FAIL=$((FAIL + 1)); echo "FAIL $1 (want $3, got ${_got:-none})"
+ echo " output: $_out"
+ fi
+}
+
+check "#8725 socket EACCES gets the connection hint" "$_EACCES_LOG" socket
+check "EPERM on a cache file gets the file hint" "$_EPERM_LOG" file
+check "unwritable cache (FetchError + path) gets the file hint" "$_CACHE_ACL_LOG" file
+check "colored (color=always) EPERM log gets the file hint" "$_COLOR_EPERM_LOG" file
+check "ENOTFOUND log gets the registry hint" "$_NETWORK_LOG" registry
+check "network failure with EPERM cleanup warnings gets the registry hint" "$_NETWORK_CLEANUP_LOG" registry
+check "403 log gets the registry hint" "$_PROXY_LOG" registry
+check "unrelated failure stays quiet" "$_UNRELATED_LOG" none
+check "empty log keeps the registry hint" "" registry
+UNSLOTH_NPM_REGISTRY="https://mirror.example/api/npm/" \
+ check "local hint survives UNSLOTH_NPM_REGISTRY" "$_EACCES_LOG" socket
+UNSLOTH_NPM_REGISTRY="https://mirror.example/api/npm/" \
+ check "UNSLOTH_NPM_REGISTRY still silences the registry hint" "$_NETWORK_LOG" none
+
+echo ""
+echo "Results: $PASS passed, $FAIL failed"
+[ "$FAIL" -eq 0 ]
diff --git a/tests/studio_setup_ps1/Studio.Setup.NpmHint.Tests.ps1 b/tests/studio_setup_ps1/Studio.Setup.NpmHint.Tests.ps1
new file mode 100644
index 00000000000..3483ce909c1
--- /dev/null
+++ b/tests/studio_setup_ps1/Studio.Setup.NpmHint.Tests.ps1
@@ -0,0 +1,140 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+# See /studio/LICENSE.AGPL-3.0
+#
+# Show-NpmRegistryHint in studio/setup.ps1: a local npm errno gets a local hint, not
+# "registry.npmjs.org looks blocked". #8725's EACCES came from the HTTP socket
+# (FetchError), so it gets the "OS refused node's connection" variant.
+
+BeforeAll {
+ . (Join-Path $PSScriptRoot 'Get-FunctionSource.ps1')
+ $candidates = @($env:SETUP_PS1_PATH, (Join-Path $PSScriptRoot '..\..\studio\setup.ps1')) | Where-Object { $_ }
+ $script:SetupPs1 = $candidates | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
+ if (-not $script:SetupPs1) { throw "Could not locate studio/setup.ps1 (set SETUP_PS1_PATH)." }
+
+ $setupText = Get-Content -Raw -LiteralPath $script:SetupPs1
+ foreach ($varName in @('NpmLocalFailureRe', 'NpmNetworkFailureRe')) {
+ $m = [regex]::Match($setupText, "(?m)^\s*\`$script:$varName\s*=\s*'[^']*'")
+ if (-not $m.Success) { throw "Could not find `$script:$varName in $script:SetupPs1." }
+ . ([scriptblock]::Create($m.Value))
+ }
+ foreach ($fn in @('Get-StudioAnsi', 'Write-StudioLine', 'Write-StudioStdoutMirror', 'step', 'substep',
+ 'Show-NpmLocalFailureHint', 'Show-NpmRegistryHint')) {
+ $src = Get-FunctionSource -Path $script:SetupPs1 -Name $fn
+ if (-not $src) { throw "Function '$fn' not found in $script:SetupPs1." }
+ . ([scriptblock]::Create($src))
+ }
+
+ $script:EaccesOutput = @'
+npm error code EACCES
+npm error FetchError: request to https://registry.npmjs.org/oxlint/-/oxlint-1.65.0.tgz failed, reason:
+npm error The operation was rejected by your operating system.
+'@
+ $script:EpermFileOutput = @'
+npm error code EPERM
+npm error syscall rename
+npm error Error: EPERM: operation not permitted, rename 'C:\npm-cache\_cacache\tmp\x'
+'@
+ $script:CacheAclOutput = @'
+npm error code EPERM
+npm error syscall mkdir
+npm error path D:\a\_temp\x\cache\_cacache
+npm error errno EPERM
+npm error FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/is-number: EPERM: operation not permitted, mkdir 'D:\a\_temp\x\cache\_cacache'
+'@
+ $script:NetworkOutput = @'
+npm error code ENOTFOUND
+npm error network request to https://registry.npmjs.org/oxlint failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
+'@
+ $script:NetworkCleanupOutput = @'
+npm warn cleanup Failed to remove some directories [
+npm warn cleanup [Error: EPERM: operation not permitted, rmdir 'C:\x\node_modules\oxlint']
+npm warn cleanup ]
+npm error code ETIMEDOUT
+npm error network request to https://registry.npmjs.org/oxlint failed
+'@
+ $script:UnrelatedOutput = @'
+npm error code ELIFECYCLE
+npm error [email protected] postinstall script failed
+'@
+
+ function Invoke-CapturingHint {
+ param([string]$FailureOutput = "")
+ $prevOut = [Console]::Out
+ $writer = New-Object System.IO.StringWriter
+ try {
+ [Console]::SetOut($writer)
+ Show-NpmRegistryHint -FailureOutput $FailureOutput 6>&1 | Out-Null
+ } finally {
+ [Console]::SetOut($prevOut)
+ }
+ return $writer.ToString()
+ }
+}
+
+Describe 'Show-NpmRegistryHint' {
+ BeforeEach {
+ $script:StudioVtOk = $false
+ $script:StudioStdoutRedirected = $true
+ $env:NO_COLOR = $null
+ $env:UNSLOTH_NPM_REGISTRY = $null
+ $env:NPM_CONFIG_REGISTRY = $null
+ }
+
+ It 'reports the #8725 socket EACCES as a blocked node connection' {
+ $out = Invoke-CapturingHint -FailureOutput $script:EaccesOutput
+ $out | Should -Match "refused node's connection"
+ $out | Should -Not -Match 'local file error'
+ $out | Should -Not -Match 'looks blocked \(corporate firewall/proxy\?\)'
+ }
+
+ It 'reports EPERM on a cache file as a local file error' {
+ $out = Invoke-CapturingHint -FailureOutput $script:EpermFileOutput
+ $out | Should -Match 'local file error'
+ $out | Should -Not -Match "refused node's connection"
+ $out | Should -Not -Match 'looks blocked \(corporate firewall/proxy\?\)'
+ }
+
+ It 'reports an unwritable cache (FetchError with a path) as a file error' {
+ $out = Invoke-CapturingHint -FailureOutput $script:CacheAclOutput
+ $out | Should -Match 'local file error'
+ $out | Should -Not -Match "refused node's connection"
+ }
+
+ It 'strips ANSI colour before matching the code line' {
+ $e = [char]27
+ $colored = "${e}[31mnpm${e}[39m ${e}[31merror${e}[39m ${e}[90mcode${e}[39m EPERM`n${e}[31mnpm${e}[39m ${e}[31merror${e}[39m syscall rename"
+ Invoke-CapturingHint -FailureOutput $colored | Should -Match 'local file error'
+ }
+
+ It 'points at the registry for a network failure' {
+ $out = Invoke-CapturingHint -FailureOutput $script:NetworkOutput
+ $out | Should -Match 'looks blocked \(corporate firewall/proxy\?\)'
+ $out | Should -Not -Match 'local file error'
+ }
+
+ It 'ignores EPERM cleanup warnings next to a network failure' {
+ $out = Invoke-CapturingHint -FailureOutput $script:NetworkCleanupOutput
+ $out | Should -Match 'looks blocked \(corporate firewall/proxy\?\)'
+ $out | Should -Not -Match 'local file error'
+ }
+
+ It 'stays quiet when nothing points at either cause' {
+ (Invoke-CapturingHint -FailureOutput $script:UnrelatedOutput).Trim() | Should -BeNullOrEmpty
+ }
+
+ It 'keeps the registry hint when no output was captured' {
+ Invoke-CapturingHint -FailureOutput "" | Should -Match 'looks blocked \(corporate firewall/proxy\?\)'
+ }
+
+ It 'prints the local hint even with UNSLOTH_NPM_REGISTRY set' {
+ $env:UNSLOTH_NPM_REGISTRY = 'https://mirror.example/api/npm/'
+ Invoke-CapturingHint -FailureOutput $script:EaccesOutput | Should -Match "refused node's connection"
+ }
+
+ It 'passes the captured output at every call site' {
+ $calls = [regex]::Matches((Get-Content -Raw -LiteralPath $script:SetupPs1), '(?m)^\s*Show-NpmRegistryHint\b[^\r\n]*') | ForEach-Object { $_.Value }
+ $calls.Count | Should -Be 2
+ foreach ($call in $calls) { $call | Should -Match '-FailureOutput \$script:SetupCommandOutput' }
+ }
+}