Fix PowerShell window closing: wrap in try/catch/finally
- Remove $ErrorActionPreference = "Stop" (caused unhandled exits) - Write-Err now throws to outer catch (shows error, stays open) - finally block always pauses with Read-Host before closing - npm output piped through Write-Host to prevent stream errors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
# OpenClaw AWS Bedrock 配置脚本 (Windows)
|
# OpenClaw AWS Bedrock 配置脚本 (Windows)
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
|
||||||
|
|
||||||
function Write-Info($msg) { Write-Host "[信息] $msg" -ForegroundColor Cyan }
|
function Write-Info($msg) { Write-Host "[信息] $msg" -ForegroundColor Cyan }
|
||||||
function Write-Ok($msg) { Write-Host "[完成] $msg" -ForegroundColor Green }
|
function Write-Ok($msg) { Write-Host "[完成] $msg" -ForegroundColor Green }
|
||||||
function Write-Warn($msg) { Write-Host "[警告] $msg" -ForegroundColor Yellow }
|
function Write-Warn($msg) { Write-Host "[警告] $msg" -ForegroundColor Yellow }
|
||||||
function Write-Err($msg) { Write-Host "[错误] $msg" -ForegroundColor Red; Read-Host "按 Enter 键退出"; return }
|
function Write-Err($msg) { Write-Host "[错误] $msg" -ForegroundColor Red; throw $msg }
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "========================================" -ForegroundColor White
|
Write-Host "========================================" -ForegroundColor White
|
||||||
@@ -235,3 +235,12 @@ Write-Host " * bedrock:InvokeModel" -ForegroundColor Yellow
|
|||||||
Write-Host " * bedrock:InvokeModelWithResponseStream" -ForegroundColor Yellow
|
Write-Host " * bedrock:InvokeModelWithResponseStream" -ForegroundColor Yellow
|
||||||
Write-Host " 或使用托管策略:AmazonBedrockFullAccess" -ForegroundColor Yellow
|
Write-Host " 或使用托管策略:AmazonBedrockFullAccess" -ForegroundColor Yellow
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "[错误] 脚本执行失败: $_" -ForegroundColor Red
|
||||||
|
Write-Host ""
|
||||||
|
} finally {
|
||||||
|
Write-Host ""
|
||||||
|
Read-Host "按 Enter 键关闭此窗口"
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,12 +3,10 @@
|
|||||||
# Installs Node.js + OpenClaw, runs natively
|
# Installs Node.js + OpenClaw, runs natively
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
|
||||||
|
|
||||||
function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }
|
function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }
|
||||||
function Write-Ok($msg) { Write-Host "[DONE] $msg" -ForegroundColor Green }
|
function Write-Ok($msg) { Write-Host "[DONE] $msg" -ForegroundColor Green }
|
||||||
function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
||||||
function Write-Err($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red; Read-Host "Press Enter to exit"; return }
|
function Write-Err($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red; throw $msg }
|
||||||
|
|
||||||
function Write-Header {
|
function Write-Header {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
@@ -18,6 +16,8 @@ function Write-Header {
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
Write-Header
|
Write-Header
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
@@ -50,7 +50,7 @@ if ($needsNode) {
|
|||||||
# Method 1: winget (built into Windows 11 / Windows 10)
|
# Method 1: winget (built into Windows 11 / Windows 10)
|
||||||
if (-not $installed -and (Get-Command winget -ErrorAction SilentlyContinue)) {
|
if (-not $installed -and (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||||
Write-Info "Installing via winget..."
|
Write-Info "Installing via winget..."
|
||||||
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
|
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements 2>$null
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
$installed = $true
|
$installed = $true
|
||||||
Write-Ok "Node.js installed via winget"
|
Write-Ok "Node.js installed via winget"
|
||||||
@@ -60,7 +60,7 @@ if ($needsNode) {
|
|||||||
# Method 2: Chocolatey
|
# Method 2: Chocolatey
|
||||||
if (-not $installed -and (Get-Command choco -ErrorAction SilentlyContinue)) {
|
if (-not $installed -and (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||||
Write-Info "Installing via Chocolatey..."
|
Write-Info "Installing via Chocolatey..."
|
||||||
choco install nodejs-lts -y
|
choco install nodejs-lts -y 2>$null
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
$installed = $true
|
$installed = $true
|
||||||
Write-Ok "Node.js installed via Chocolatey"
|
Write-Ok "Node.js installed via Chocolatey"
|
||||||
@@ -69,7 +69,6 @@ if ($needsNode) {
|
|||||||
|
|
||||||
# Method 3: Manual download prompt
|
# Method 3: Manual download prompt
|
||||||
if (-not $installed) {
|
if (-not $installed) {
|
||||||
Write-Host ""
|
|
||||||
Write-Err "Could not install Node.js automatically. Please install manually and re-run this script:`n`n Download: https://nodejs.org/en/download/`n`n After installing, reopen PowerShell and run this script again."
|
Write-Err "Could not install Node.js automatically. Please install manually and re-run this script:`n`n Download: https://nodejs.org/en/download/`n`n After installing, reopen PowerShell and run this script again."
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +100,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($needsInstall) {
|
if ($needsInstall) {
|
||||||
npm install -g openclaw@latest
|
npm install -g openclaw@latest 2>&1 | Write-Host
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Err "OpenClaw installation failed. Please run manually: npm install -g openclaw@latest"
|
Write-Err "OpenClaw installation failed. Please run manually: npm install -g openclaw@latest"
|
||||||
}
|
}
|
||||||
@@ -150,3 +149,12 @@ Write-Host " 2. Start OpenClaw: openclaw" -ForegroundColor Gray
|
|||||||
Write-Host " 3. Add skills (optional): openclaw configure --section skills" -ForegroundColor Gray
|
Write-Host " 3. Add skills (optional): openclaw configure --section skills" -ForegroundColor Gray
|
||||||
Write-Host " 4. Browse available skills: openclaw skills" -ForegroundColor Gray
|
Write-Host " 4. Browse available skills: openclaw skills" -ForegroundColor Gray
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "[ERROR] Script failed: $_" -ForegroundColor Red
|
||||||
|
Write-Host ""
|
||||||
|
} finally {
|
||||||
|
Write-Host ""
|
||||||
|
Read-Host "Press Enter to close this window"
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,12 +3,10 @@
|
|||||||
# 安装 Node.js + OpenClaw,原生 Windows 运行
|
# 安装 Node.js + OpenClaw,原生 Windows 运行
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
|
||||||
|
|
||||||
function Write-Info($msg) { Write-Host "[信息] $msg" -ForegroundColor Cyan }
|
function Write-Info($msg) { Write-Host "[信息] $msg" -ForegroundColor Cyan }
|
||||||
function Write-Ok($msg) { Write-Host "[完成] $msg" -ForegroundColor Green }
|
function Write-Ok($msg) { Write-Host "[完成] $msg" -ForegroundColor Green }
|
||||||
function Write-Warn($msg) { Write-Host "[警告] $msg" -ForegroundColor Yellow }
|
function Write-Warn($msg) { Write-Host "[警告] $msg" -ForegroundColor Yellow }
|
||||||
function Write-Err($msg) { Write-Host "[错误] $msg" -ForegroundColor Red; Read-Host "按 Enter 键退出"; return }
|
function Write-Err($msg) { Write-Host "[错误] $msg" -ForegroundColor Red; throw $msg }
|
||||||
|
|
||||||
function Write-Header {
|
function Write-Header {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
@@ -18,6 +16,8 @@ function Write-Header {
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
Write-Header
|
Write-Header
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
@@ -50,7 +50,7 @@ if ($needsNode) {
|
|||||||
# 方式 1: winget(Windows 11 / Windows 10 自带)
|
# 方式 1: winget(Windows 11 / Windows 10 自带)
|
||||||
if (-not $installed -and (Get-Command winget -ErrorAction SilentlyContinue)) {
|
if (-not $installed -and (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||||
Write-Info "使用 winget 安装..."
|
Write-Info "使用 winget 安装..."
|
||||||
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
|
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements 2>$null
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
$installed = $true
|
$installed = $true
|
||||||
Write-Ok "Node.js 已通过 winget 安装"
|
Write-Ok "Node.js 已通过 winget 安装"
|
||||||
@@ -60,7 +60,7 @@ if ($needsNode) {
|
|||||||
# 方式 2: Chocolatey
|
# 方式 2: Chocolatey
|
||||||
if (-not $installed -and (Get-Command choco -ErrorAction SilentlyContinue)) {
|
if (-not $installed -and (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||||
Write-Info "使用 Chocolatey 安装..."
|
Write-Info "使用 Chocolatey 安装..."
|
||||||
choco install nodejs-lts -y
|
choco install nodejs-lts -y 2>$null
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
$installed = $true
|
$installed = $true
|
||||||
Write-Ok "Node.js 已通过 Chocolatey 安装"
|
Write-Ok "Node.js 已通过 Chocolatey 安装"
|
||||||
@@ -69,8 +69,7 @@ if ($needsNode) {
|
|||||||
|
|
||||||
# 方式 3: 手动下载提示
|
# 方式 3: 手动下载提示
|
||||||
if (-not $installed) {
|
if (-not $installed) {
|
||||||
Write-Host ""
|
Write-Err "无法自动安装 Node.js。请手动下载安装:`n`n 下载地址:https://nodejs.cn/download/`n 或:https://nodejs.org/en/download/`n`n 安装完成后重新打开 PowerShell 运行此脚本。"
|
||||||
Write-Err "无法自动安装 Node.js。请手动安装后重新运行此脚本:`n`n 下载地址:https://nodejs.cn/download/`n 或:https://nodejs.org/en/download/`n`n 安装完成后重新打开 PowerShell 运行此脚本。"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 刷新 PATH
|
# 刷新 PATH
|
||||||
@@ -101,7 +100,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($needsInstall) {
|
if ($needsInstall) {
|
||||||
npm install -g openclaw@latest
|
npm install -g openclaw@latest 2>&1 | Write-Host
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Err "OpenClaw 安装失败。请手动运行:npm install -g openclaw@latest"
|
Write-Err "OpenClaw 安装失败。请手动运行:npm install -g openclaw@latest"
|
||||||
}
|
}
|
||||||
@@ -150,3 +149,12 @@ Write-Host " 2. 开始使用 OpenClaw:openclaw" -ForegroundColor Gray
|
|||||||
Write-Host " 3. 添加技能(可选):openclaw configure --section skills" -ForegroundColor Gray
|
Write-Host " 3. 添加技能(可选):openclaw configure --section skills" -ForegroundColor Gray
|
||||||
Write-Host " 4. 浏览可用技能:openclaw skills" -ForegroundColor Gray
|
Write-Host " 4. 浏览可用技能:openclaw skills" -ForegroundColor Gray
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "[错误] 脚本执行失败: $_" -ForegroundColor Red
|
||||||
|
Write-Host ""
|
||||||
|
} finally {
|
||||||
|
Write-Host ""
|
||||||
|
Read-Host "按 Enter 键关闭此窗口"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user