fix: 将退出原因写入 start.ps1.log 便于闪退排查
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run

- 新增 Write-Log 与日志文件 start.ps1.log
- 脚本加载/正常结束/错误退出均写入日志
- trap 捕获异常时写入错误信息与堆栈
- README 补充日志位置说明

Made-with: Cursor
This commit is contained in:
wangbo 2026-03-10 22:15:54 +08:00
parent fe370bd5bc
commit f37fd958e1
2 changed files with 28 additions and 6 deletions

View File

@ -285,6 +285,8 @@ powershell -ExecutionPolicy Bypass -File .\start.ps1
3. 按提示选择 [1] 本地访问 或 [2] 局域网访问,脚本将自动配置并启动 Docker 服务。
4. 若窗口闪退,可查看日志 `start.ps1.log`(与 start.ps1 同目录,或 `%TEMP%\start.ps1.log`)获取退出原因。
### 启用HTTPS
1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名]
2. [修改.env文件]修改如下两个环境变量为如下的对应的值

View File

@ -4,13 +4,30 @@
# 一行命令: git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1
$ErrorActionPreference = "Stop"
$script:LogFile = Join-Path (if ($PSScriptRoot) { $PSScriptRoot } else { $env:TEMP }) "start.ps1.log"
# 尽早写入启动标记,便于闪退时排查
try { "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === 脚本加载 ===" | Out-File -FilePath $script:LogFile -Append -Encoding utf8 } catch { }
function Write-Log {
param([string]$Msg)
try {
$line = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] $Msg"
Add-Content -Path $script:LogFile -Value $line -Encoding UTF8 -ErrorAction SilentlyContinue
} catch { }
}
trap {
Write-Host ""
Write-Host "========================================" -ForegroundColor Red
Write-Host " 发生错误(便于 Debug" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
if ($_.ScriptStackTrace) { Write-Host "`n$($_.ScriptStackTrace)" }
$errMsg = $_.Exception.Message
$errStack = if ($_.ScriptStackTrace) { " | 堆栈: $($_.ScriptStackTrace)" } else { "" }
Write-Log "错误退出: $errMsg$errStack"
try {
Write-Host ""
Write-Host "========================================" -ForegroundColor Red
Write-Host " 发生错误,详见日志: $script:LogFile" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host $errMsg -ForegroundColor Red
if ($errStack) { Write-Host $errStack }
} catch { }
Wait-ForExit
exit 1
}
@ -280,6 +297,9 @@ function Main {
Wait-ForExit
}
Write-Log "=== 脚本启动 ==="
Write-Host "EasyAI Windows 部署脚本启动中..." -ForegroundColor Cyan
Write-Host "日志文件: $script:LogFile"
Write-Host ""
Main
Write-Log "=== 脚本正常结束 ==="