From 0f6044d65ea8585f162a1fb8344f57f4c6641def Mon Sep 17 00:00:00 2001 From: coso Date: Sun, 22 Feb 2026 16:33:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=9D=A1=E6=B6=88=E6=81=AF=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题分析: - 用户报告 v0.70 在发送第一条消息时闪退,v0.60 正常工作 - 从 v0.68/v0.69/v0.70 开始出现问题 修复内容: 1. 移除危险的 unwrap() 调用 (bootstrap.rs:147) - 将 .unwrap() 改为 .expect() 提供详细错误信息 - 如果 tokio runtime 创建失败,现在会显示具体错误而不是 panic 2. 添加前端错误处理 (AgentChat/index.tsx) - 在 handleSend 函数中添加 try-catch 错误处理 - 捕获 sendMessage 调用中的异常 - 显示友好的错误提示并恢复输入内容 3. 验证模型过滤逻辑 (modelThemePolicy.ts) - 确认已有完善的回退机制 - 过滤后无模型时会返回原始列表 - ModelSelector 在空列表时显示提示而非崩溃 4. 验证加密模块 - ChaCha20-Poly1305 加密仅在测试中使用 - 实际使用的是自定义 XOR 加密 - 加密初始化不会导致启动时崩溃 相关提交: - v0.69.0 (bd6d487d): 新增模型主题策略 - v0.70.0 (0c357c8b): 新增加密模块和安全中间件 参考: test-crash-fix.md --- src-tauri/src/app/bootstrap.rs | 5 ++++- src/components/agent/chat/index.tsx | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/app/bootstrap.rs b/src-tauri/src/app/bootstrap.rs index 49c1e8f49..3f3b26a45 100644 --- a/src-tauri/src/app/bootstrap.rs +++ b/src-tauri/src/app/bootstrap.rs @@ -144,7 +144,10 @@ pub fn init_states(config: &Config) -> Result { // 使用 tokio runtime 来设置全局 store let rt = tokio::runtime::Handle::try_current().unwrap_or_else(|_| { // 如果没有 runtime,创建一个临时的 - tokio::runtime::Runtime::new().unwrap().handle().clone() + tokio::runtime::Runtime::new() + .expect("Failed to create tokio runtime: 系统资源不足或配置错误") + .handle() + .clone() }); rt.block_on(async { if let Err(e) = aster::session::set_global_session_store(session_store).await { diff --git a/src/components/agent/chat/index.tsx b/src/components/agent/chat/index.tsx index bbea594e7..a18f0f265 100644 --- a/src/components/agent/chat/index.tsx +++ b/src/components/agent/chat/index.tsx @@ -975,14 +975,22 @@ export function AgentChatPage({ setInput(""); setMentionedCharacters([]); // 清空引用的角色 - await sendMessage( - text, - images || [], - webSearch, - thinking, - false, - sendExecutionStrategy, - ); + + try { + await sendMessage( + text, + images || [], + webSearch, + thinking, + false, + sendExecutionStrategy, + ); + } catch (error) { + console.error("[AgentChat] 发送消息失败:", error); + toast.error(`发送失败: ${error instanceof Error ? error.message : String(error)}`); + // 恢复输入内容,让用户可以重试 + setInput(sourceText); + } }, [input, mentionedCharacters, projectId, sendMessage], );