fix: wrap main execution in try/catch to show errors instead of silent exit

This commit is contained in:
i
2026-06-02 01:09:40 +08:00
parent 437d41bd48
commit 98384486c2
+44 -36
View File
@@ -1041,45 +1041,53 @@ function Invoke-Upgrade {
# ───────────────────────────────────────── # ─────────────────────────────────────────
# 主流程 # 主流程
# ───────────────────────────────────────── # ─────────────────────────────────────────
"" | Out-File $LOG_FILE try {
"" | Out-File $LOG_FILE
# 检测是否是 iex / 管道执行(如 irm | iex) # 检测是否是 iex / 管道执行(如 irm | iex)
$isIexExecution = -not $PSCommandPath $isIexExecution = -not $PSCommandPath
Setup-InstallDir Setup-InstallDir
Check-Prerequisites Check-Prerequisites
Collect-Status Collect-Status
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor White
Write-Host "║ HAPI 系统状态 ║" -ForegroundColor White
Write-Host "╚══════════════════════════════════════════════════════════════════╝" -ForegroundColor White
Write-Host ""
Print-Status
# 非交互模式(irm | iex)
if ($isIexExecution) {
if ($Upgrade) {
Invoke-Upgrade
Start-Sleep 3
exit
}
if ($Force -or $Source -or $SkipHub -or $InstallDir) {
Invoke-Install
Start-Sleep 3
exit
}
if (-not $script:STATUS_CLI_INSTALLED) {
Write-Host ""
Write-Warn "HAPI CLI 未安装"
Write-Warn "请使用 -Source / -Force 等参数指定操作,或直接运行 install.ps1 进入交互模式"
}
Write-Host "" Write-Host ""
Start-Sleep 3 Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor White
exit Write-Host "║ HAPI 系统状态 ║" -ForegroundColor White
} Write-Host "╚══════════════════════════════════════════════════════════════════╝" -ForegroundColor White
Write-Host ""
Print-Status
# 交互菜单 # 非交互模式(irm | iex)
while ($true) { if ($isIexExecution) {
Main-Menu if ($Upgrade) {
Invoke-Upgrade
Start-Sleep 3
exit
}
if ($Force -or $Source -or $SkipHub -or $InstallDir) {
Invoke-Install
Start-Sleep 3
exit
}
if (-not $script:STATUS_CLI_INSTALLED) {
Write-Host ""
Write-Warn "HAPI CLI 未安装"
Write-Warn "请使用 -Source / -Force 等参数指定操作,或直接运行 install.ps1 进入交互模式"
}
Write-Host ""
Start-Sleep 3
exit
}
# 交互菜单
while ($true) {
Main-Menu
}
} catch {
Write-Host ""
Write-Err "脚本错误: $_"
Write-Host "按 Enter 退出..."
$null = Read-Host
exit 1
} }