Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

Refactor PowerShell script for improved error handling

KageBinarye737941bccdc
diff --git a/scripts/install/install.ps1 b/scripts/install/install.ps1
index c964dab7..ef53e16b 100644
--- a/scripts/install/install.ps1
+++ b/scripts/install/install.ps1
@@ -31,10 +31,49 @@ $NodeMinMajor = 20
# ── Helpers ──────────────────────────────────────────────────────────────────
-function Write-Ok($msg) { Write-Host " [ok] $msg" -ForegroundColor Green }
-function Write-Warn($msg) { Write-Host " [!!] $msg" -ForegroundColor Yellow }
+function Pause-On-Failure {
+ if ($Host.Name -eq "ConsoleHost") {
+ Write-Host ""
+ Read-Host "Press Enter to exit"
+ }
+}
+
+function Write-Ok($msg) {
+ Write-Host " [ok] $msg" -ForegroundColor Green
+}
+
+function Write-Warn($msg) {
+ Write-Host " [!!] $msg" -ForegroundColor Yellow
+}
+
function Write-Err($msg) {
Write-Host " [error] $msg" -ForegroundColor Red
+ Pause-On-Failure
+ exit 1
+}
+
+trap {
+ Write-Host ""
+ Write-Host "Ix installer failed." -ForegroundColor Red
+ Write-Host ""
+ Write-Host "Error:" -ForegroundColor Red
+ Write-Host " $($_.Exception.Message)"
+ Write-Host ""
+
+ if ($_.InvocationInfo -and $_.InvocationInfo.PositionMessage) {
+ Write-Host "Location:" -ForegroundColor Yellow
+ Write-Host $_.InvocationInfo.PositionMessage
+ Write-Host ""
+ }
+
+ Write-Host "Troubleshooting:"
+ Write-Host " 1. Make sure Docker Desktop is running."
+ Write-Host " 2. Try running this script from an already-open PowerShell window."
+ Write-Host " 3. Re-run with:"
+ Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1"
+ Write-Host ""
+
+ Pause-On-Failure
exit 1
}
@@ -50,6 +89,7 @@ function Test-Healthy {
function Get-LatestVersion {
if ($env:IX_VERSION) { return $env:IX_VERSION }
+
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$GithubOrg/$GithubRepo/releases/latest" -ErrorAction Stop
return $release.tag_name -replace '^v', ''
@@ -58,6 +98,30 @@ function Get-LatestVersion {
}
}
+function Test-DockerRunning {
+ $dockerInfoOutput = & docker info 2>&1
+ $dockerExitCode = $LASTEXITCODE
+
+ if ($dockerExitCode -eq 0) {
+ return $true
+ }
+
+ Write-Host ""
+ Write-Host " Docker is installed but Docker Engine is not reachable." -ForegroundColor Yellow
+ Write-Host " Start Docker Desktop, wait until it says Docker is running, then re-run this installer."
+ Write-Host ""
+
+ if ($dockerInfoOutput) {
+ Write-Host " Docker output:"
+ $dockerInfoOutput | ForEach-Object {
+ Write-Host " $_"
+ }
+ Write-Host ""
+ }
+
+ return $false
+}
+
# ══════════════════════════════════════════════════════════════════════════════
# MAIN
# ══════════════════════════════════════════════════════════════════════════════
@@ -79,7 +143,8 @@ Write-Host "-- 1. Node.js (runtime) --" -ForegroundColor White
function Get-NodeMajorVersion {
try {
- $ver = & node -v 2>&1
+ $ver = & node -v 2>$null
+ if (-not $ver) { return 0 }
return [int]($ver -replace '^v','').Split('.')[0]
} catch {
return 0
@@ -108,7 +173,7 @@ function Install-NodeJS($action) {
Write-Host " $action Node.js via official installer..."
$nodeInstaller = "$env:TEMP\node-install.msi"
Write-Host " Downloading Node.js LTS installer..."
- # Resolve latest LTS version
+
try {
$nodeIndex = Invoke-RestMethod -Uri "https://nodejs.org/dist/index.json" -ErrorAction Stop
$ltsEntry = $nodeIndex | Where-Object { $_.lts -ne $false } | Select-Object -First 1
@@ -116,14 +181,15 @@ function Install-NodeJS($action) {
} catch {
$nodeVer = "22.14.0"
}
+
Invoke-WebRequest -Uri "https://nodejs.org/dist/v$nodeVer/node-v$nodeVer-x64.msi" `
- -OutFile $nodeInstaller -UseBasicParsing
- Write-Host " Running installer (this may take a moment)..."
+ -OutFile $nodeInstaller -UseBasicParsing -ErrorAction Stop
+
+ Write-Host " Running installer..."
Start-Process msiexec.exe -ArgumentList "/i", $nodeInstaller, "/qn", "/norestart" -Wait -NoNewWindow
Remove-Item $nodeInstaller -Force -ErrorAction SilentlyContinue
}
- # Refresh PATH for current session
$machinePath = [Environment]::GetEnvironmentVariable("PATH", "Machine")
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$env:Path = "$machinePath;$userPath"
@@ -132,27 +198,33 @@ function Install-NodeJS($action) {
$nodeCmd = Get-Command node -ErrorAction SilentlyContinue
if ($nodeCmd) {
$currentMajor = Get-NodeMajorVersion
+
if ($currentMajor -ge $NodeMinMajor) {
- $nodeVer = & node -v 2>&1
+ $nodeVer = & node -v 2>$null
Write-Ok "Node.js $nodeVer is installed (>= $NodeMinMajor required)"
} else {
- $nodeVer = & node -v 2>&1
+ $nodeVer = & node -v 2>$null
Write-Warn "Node.js $nodeVer is too old (>= $NodeMinMajor required)"
+
Install-NodeJS "Upgrading"
+
$currentMajor = Get-NodeMajorVersion
if ($currentMajor -lt $NodeMinMajor) {
Write-Err "Node.js upgrade failed. Install Node.js $NodeMinMajor+ manually: https://nodejs.org/"
}
- $nodeVer = & node -v 2>&1
+
+ $nodeVer = & node -v 2>$null
Write-Ok "Node.js upgraded to $nodeVer"
}
} else {
Install-NodeJS "Installing"
+
$nodeCmd = Get-Command node -ErrorAction SilentlyContinue
if (-not $nodeCmd) {
Write-Err "Node.js installation failed. Install Node.js $NodeMinMajor+ manually: https://nodejs.org/"
}
- $nodeVer = & node -v 2>&1
+
+ $nodeVer = & node -v 2>$null
Write-Ok "Node.js $nodeVer installed"
}
@@ -165,9 +237,10 @@ if ($env:IX_SKIP_BACKEND -eq "1") {
Write-Host " (skipped via IX_SKIP_BACKEND=1)"
} else {
$dockerCmd = Get-Command docker -ErrorAction SilentlyContinue
+
if (-not $dockerCmd) {
Write-Host ""
- Write-Host " Docker Desktop is required to run the IX backend." -ForegroundColor Yellow
+ Write-Host " Docker Desktop is required to run the Ix backend." -ForegroundColor Yellow
Write-Host ""
Write-Host " Install Docker Desktop for Windows:"
Write-Host " https://docs.docker.com/desktop/install/windows-install/"
@@ -175,17 +248,15 @@ if ($env:IX_SKIP_BACKEND -eq "1") {
Write-Host " Or via winget:"
Write-Host " winget install Docker.DockerDesktop"
Write-Host ""
+
Write-Err "Install Docker Desktop and re-run this installer."
}
+
Write-Ok "Docker is installed"
- try {
- $null = docker info 2>&1
+ if (Test-DockerRunning) {
Write-Ok "Docker is running"
- } catch {
- Write-Host ""
- Write-Host " Docker is installed but not running." -ForegroundColor Yellow
- Write-Host " Start Docker Desktop and re-run this installer."
+ } else {
Write-Err "Docker is not running."
}
}
@@ -206,27 +277,39 @@ if ($env:IX_SKIP_BACKEND -eq "1") {
Write-Host " Downloading docker-compose.yml..."
Invoke-WebRequest -Uri "$GithubRaw/docker-compose.standalone.yml" `
- -OutFile "$ComposeDir\docker-compose.yml" -UseBasicParsing
+ -OutFile "$ComposeDir\docker-compose.yml" -UseBasicParsing -ErrorAction Stop
Write-Ok "Downloaded docker-compose.yml"
Write-Host " Starting backend services..."
docker compose -f "$ComposeDir\docker-compose.yml" up -d --pull always
+ if ($LASTEXITCODE -ne 0) {
+ Write-Err "Docker Compose failed to start backend services."
+ }
Write-Host " Waiting for services to become healthy..."
$healthy = $false
+
for ($i = 0; $i -lt 30; $i++) {
- if (Test-Healthy) { $healthy = $true; break }
+ if (Test-Healthy) {
+ $healthy = $true
+ break
+ }
+
Write-Host -NoNewline "."
Start-Sleep -Seconds 2
}
+
Write-Host ""
if ($healthy) {
Write-Ok "Backend is ready"
} else {
- Write-Warn "Backend may still be starting. Check: docker compose -f $ComposeDir\docker-compose.yml logs"
+ Write-Warn "Backend may still be starting."
+ Write-Host " Check logs with:"
+ Write-Host " docker compose -f `"$ComposeDir\docker-compose.yml`" logs"
}
+
Write-Host " Memory Layer: http://localhost:8090"
Write-Host " ArangoDB: http://localhost:8529"
}
@@ -245,7 +328,11 @@ New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
$existingVersion = ""
if (Test-Path "$IxBin\ix.cmd") {
- try { $existingVersion = & "$IxBin\ix.cmd" --version 2>&1 } catch {}
+ try {
+ $existingVersion = & "$IxBin\ix.cmd" --version 2>$null
+ } catch {
+ $existingVersion = ""
+ }
}
if ($existingVersion -eq $Version) {
@@ -253,23 +340,26 @@ if ($existingVersion -eq $Version) {
} else {
Write-Host " Downloading ix CLI v$Version..."
$tmpZip = "$env:TEMP\$TarballName"
+
try {
- Invoke-WebRequest -Uri $TarballUrl -OutFile $tmpZip -UseBasicParsing
+ Invoke-WebRequest -Uri $TarballUrl -OutFile $tmpZip -UseBasicParsing -ErrorAction Stop
} catch {
Write-Warn "Could not download pre-built CLI from:"
Write-Warn " $TarballUrl"
Write-Host ""
Write-Host " Build from source instead:"
Write-Host " git clone https://github.com/$GithubOrg/$GithubRepo.git"
- Write-Host " cd $GithubRepo; .\setup.sh"
+ Write-Host " cd $GithubRepo"
+ Write-Host " .\setup.sh"
+
Write-Err "CLI download failed."
}
Expand-Archive -Path $tmpZip -DestinationPath $InstallDir -Force
- Remove-Item $tmpZip -Force
+ Remove-Item $tmpZip -Force -ErrorAction SilentlyContinue
+
Write-Ok "Extracted CLI to $InstallDir"
- # Create batch wrapper
@"
@echo off
"%~dp0..\cli\ix-$Version-windows-amd64\ix.cmd" %*
@@ -277,14 +367,12 @@ if ($existingVersion -eq $Version) {
Write-Ok "Installed: $IxBin\ix.cmd"
- # Add to PATH if not already there
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$IxBin*") {
[Environment]::SetEnvironmentVariable("PATH", "$IxBin;$userPath", "User")
Write-Ok "Added $IxBin to user PATH"
}
- # Make ix available in the current session immediately
if ($env:Path -notlike "*$IxBin*") {
$env:Path = "$IxBin;$env:Path"
}
@@ -297,21 +385,23 @@ Write-Host "+" + ("=" * 42) + "+" -ForegroundColor Green
Write-Host "| Ix is ready! |" -ForegroundColor Green
Write-Host "+" + ("=" * 42) + "+" -ForegroundColor Green
Write-Host ""
-Write-Host " Backend: http://localhost:8090"
-Write-Host " ArangoDB: http://localhost:8529"
-Write-Host ""
-# Verify CLI works
+if ($env:IX_SKIP_BACKEND -ne "1") {
+ Write-Host " Backend: http://localhost:8090"
+ Write-Host " ArangoDB: http://localhost:8529"
+ Write-Host ""
+}
+
$ixCmd = Get-Command ix -ErrorAction SilentlyContinue
if ($ixCmd) {
try {
- $cliVersion = & ix --version 2>&1
+ $cliVersion = & ix --version 2>$null
Write-Ok "ix CLI v$cliVersion is working"
} catch {
- Write-Warn "ix installed but could not verify — open a new terminal to use it"
+ Write-Warn "ix installed but could not verify. Open a new terminal to use it."
}
} else {
- Write-Warn "ix is not in PATH yet — open a new terminal to use it"
+ Write-Warn "ix is not in PATH yet. Open a new terminal to use it."
}
Write-Host ""