Skip to content

Commit c72c827

Browse files
committed
fix(installer): print npm debug logs on Windows install failure
1 parent 92242f4 commit c72c827

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎scripts/install.ps1‎

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,84 @@ function Test-NpmConfigRawKey {
10601060
return $false
10611061
}
10621062

1063+
function Add-NpmCacheCandidate {
1064+
param(
1065+
[System.Collections.Generic.List[string]]$Candidates,
1066+
[object]$Path
1067+
)
1068+
foreach ($rawPath in @($Path)) {
1069+
$trimmed = "$rawPath".Trim()
1070+
if (-not [string]::IsNullOrWhiteSpace($trimmed) -and -not $Candidates.Contains($trimmed)) {
1071+
$Candidates.Add($trimmed)
1072+
}
1073+
}
1074+
}
1075+
1076+
function Get-NpmDebugLogRootCandidates {
1077+
$candidates = New-Object System.Collections.Generic.List[string]
1078+
Add-NpmCacheCandidate -Candidates $candidates -Path $env:NPM_CONFIG_CACHE
1079+
1080+
$detectedCache = (Invoke-NpmCommand -Arguments @("config", "get", "cache") 2>$null)
1081+
if ($LASTEXITCODE -eq 0) {
1082+
Add-NpmCacheCandidate -Candidates $candidates -Path $detectedCache
1083+
}
1084+
1085+
if ($env:LOCALAPPDATA) {
1086+
Add-NpmCacheCandidate -Candidates $candidates -Path (Join-Path $env:LOCALAPPDATA "npm-cache")
1087+
}
1088+
if ($env:APPDATA) {
1089+
Add-NpmCacheCandidate -Candidates $candidates -Path (Join-Path $env:APPDATA "npm-cache")
1090+
}
1091+
if ($env:USERPROFILE) {
1092+
Add-NpmCacheCandidate -Candidates $candidates -Path (Join-Path $env:USERPROFILE "AppData\Local\npm-cache")
1093+
}
1094+
1095+
return $candidates
1096+
}
1097+
1098+
function Get-LatestNpmDebugLogPath {
1099+
foreach ($cacheDir in (Get-NpmDebugLogRootCandidates)) {
1100+
$logDir = Join-Path $cacheDir "_logs"
1101+
if (-not (Test-Path -LiteralPath $logDir -PathType Container)) {
1102+
continue
1103+
}
1104+
$latestLog = Get-ChildItem -LiteralPath $logDir -Filter "*-debug-*.log" -File -ErrorAction SilentlyContinue |
1105+
Sort-Object LastWriteTimeUtc -Descending |
1106+
Select-Object -First 1
1107+
if ($latestLog) {
1108+
return $latestLog.FullName
1109+
}
1110+
}
1111+
return $null
1112+
}
1113+
1114+
function Write-NpmInstallFailureDetails {
1115+
param([object[]]$Output)
1116+
$printedOutput = $false
1117+
foreach ($line in @($Output)) {
1118+
if ($null -eq $line) {
1119+
continue
1120+
}
1121+
$text = "$line"
1122+
if ([string]::IsNullOrWhiteSpace($text)) {
1123+
continue
1124+
}
1125+
Write-Host $text
1126+
$printedOutput = $true
1127+
}
1128+
1129+
$latestLog = Get-LatestNpmDebugLogPath
1130+
if ($latestLog) {
1131+
Write-Host "Latest npm debug log ($latestLog):" -ForegroundColor Yellow
1132+
Get-Content -LiteralPath $latestLog -Tail 120 -ErrorAction SilentlyContinue | ForEach-Object { Write-Host $_ }
1133+
return
1134+
}
1135+
1136+
if (-not $printedOutput) {
1137+
Write-Host "npm produced no console output and no npm debug log was found." -ForegroundColor Yellow
1138+
}
1139+
}
1140+
10631141
function Install-OpenClaw {
10641142
if ([string]::IsNullOrWhiteSpace($Tag)) {
10651143
$Tag = "latest"
@@ -1119,7 +1197,7 @@ function Install-OpenClaw {
11191197
Write-Host "Re-run with verbose output to see the full error:" -ForegroundColor Yellow
11201198
Write-Host ' powershell -c "irm https://openclaw.ai/install.ps1 | iex"' -ForegroundColor Cyan
11211199
}
1122-
$npmOutput | ForEach-Object { Write-Host $_ }
1200+
Write-NpmInstallFailureDetails -Output $npmOutput
11231201
return $false
11241202
}
11251203
} finally {

‎test/scripts/install-ps1.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ describe("install.ps1 failure handling", () => {
112112
expect(npmInstallBody).toContain(
113113
"$env:NODE_LLAMA_CPP_SKIP_DOWNLOAD = $prevNodeLlamaSkipDownload",
114114
);
115+
expect(npmInstallBody).toContain("Write-NpmInstallFailureDetails -Output $npmOutput");
116+
expect(source).toContain("function Get-LatestNpmDebugLogPath {");
117+
expect(source).toContain("Get-Content -LiteralPath $latestLog -Tail 120");
115118
});
116119

117120
it("runs Windows command shims from a Windows-local cwd", () => {

0 commit comments

Comments
 (0)