fix: wrap main execution in try/catch to show errors instead of silent exit
This commit is contained in:
+25
-17
@@ -1041,24 +1041,25 @@ 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 ""
|
||||||
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor White
|
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor White
|
||||||
Write-Host "║ HAPI 系统状态 ║" -ForegroundColor White
|
Write-Host "║ HAPI 系统状态 ║" -ForegroundColor White
|
||||||
Write-Host "╚══════════════════════════════════════════════════════════════════╝" -ForegroundColor White
|
Write-Host "╚══════════════════════════════════════════════════════════════════╝" -ForegroundColor White
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Print-Status
|
Print-Status
|
||||||
|
|
||||||
# 非交互模式(irm | iex)
|
# 非交互模式(irm | iex)
|
||||||
if ($isIexExecution) {
|
if ($isIexExecution) {
|
||||||
if ($Upgrade) {
|
if ($Upgrade) {
|
||||||
Invoke-Upgrade
|
Invoke-Upgrade
|
||||||
Start-Sleep 3
|
Start-Sleep 3
|
||||||
@@ -1077,9 +1078,16 @@ if ($isIexExecution) {
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
Start-Sleep 3
|
Start-Sleep 3
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# 交互菜单
|
# 交互菜单
|
||||||
while ($true) {
|
while ($true) {
|
||||||
Main-Menu
|
Main-Menu
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Err "脚本错误: $_"
|
||||||
|
Write-Host "按 Enter 退出..."
|
||||||
|
$null = Read-Host
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user