fix: add error handling and cleanup to install scripts

- Add git prerequisite check before cloning
- Check $LASTEXITCODE after git clone and go build
- Wrap build logic in try/finally for guaranteed temp cleanup
- Add error check after core setup command in batch file
- Show warning if core doctor reports issues

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
unknown 2026-02-01 00:07:45 +11:00
parent 86a80ec2e1
commit 2e034f43f2
No known key found for this signature in database
GPG key ID: FE478DD75EE21194
2 changed files with 30 additions and 11 deletions

View file

@ -35,6 +35,9 @@ function Download-Binary {
# Build from source # Build from source
function Build-FromSource { function Build-FromSource {
if (-not (Test-Command git)) {
Write-Err "Git is required to build from source. Run '.\scripts\install-deps.ps1' first"
}
if (-not (Test-Command go)) { if (-not (Test-Command go)) {
Write-Err "Go is required to build from source. Run '.\scripts\install-deps.ps1' first" Write-Err "Go is required to build from source. Run '.\scripts\install-deps.ps1' first"
} }
@ -42,20 +45,32 @@ function Build-FromSource {
$tmpdir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString()) $tmpdir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Force -Path $tmpdir | Out-Null New-Item -ItemType Directory -Force -Path $tmpdir | Out-Null
Write-Info "Cloning $Repo..." try {
$cloneDir = Join-Path $tmpdir "Core" Write-Info "Cloning $Repo..."
git clone --depth 1 "https://github.com/$Repo.git" $cloneDir $cloneDir = Join-Path $tmpdir "Core"
git clone --depth 1 "https://github.com/$Repo.git" $cloneDir
if ($LASTEXITCODE -ne 0) {
Write-Err "Failed to clone repository"
}
Write-Info "Building core CLI..." Write-Info "Building core CLI..."
Push-Location $cloneDir Push-Location $cloneDir
go build -o core.exe . go build -o core.exe .
Pop-Location if ($LASTEXITCODE -ne 0) {
Pop-Location
Write-Err "Go build failed"
}
Pop-Location
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Move-Item (Join-Path $cloneDir "core.exe") (Join-Path $InstallDir "core.exe") -Force Move-Item (Join-Path $cloneDir "core.exe") (Join-Path $InstallDir "core.exe") -Force
Remove-Item -Recurse -Force $tmpdir Write-Info "Built and installed to $InstallDir\core.exe"
Write-Info "Built and installed to $InstallDir\core.exe" } finally {
if (Test-Path $tmpdir) {
Remove-Item -Recurse -Force $tmpdir -ErrorAction SilentlyContinue
}
}
} }
# Add to PATH # Add to PATH

View file

@ -39,11 +39,15 @@ REM Run doctor
echo. echo.
echo === Verifying environment === echo === Verifying environment ===
call "%LOCALAPPDATA%\Programs\core\core.exe" doctor call "%LOCALAPPDATA%\Programs\core\core.exe" doctor
if !errorlevel! neq 0 (
echo WARNING: core doctor reported issues
)
REM Clone repos REM Clone repos
echo. echo.
echo === Cloning repositories === echo === Cloning repositories ===
call "%LOCALAPPDATA%\Programs\core\core.exe" setup call "%LOCALAPPDATA%\Programs\core\core.exe" setup
if !errorlevel! neq 0 goto :error
echo. echo.
echo === Setup complete! === echo === Setup complete! ===