fix(modelBridge): move OpenAI constructor inside try-catch (ELECTRON-6X)#1797
Merged
fix(modelBridge): move OpenAI constructor inside try-catch (ELECTRON-6X)#1797
Conversation
… unhandled rejection The previous fix (PR #1589) added apiKey guards but left the OpenAI constructor outside try-catch blocks. On OpenAI SDK v5, the constructor can throw 'Missing credentials' for whitespace-only keys that pass the falsy check. This caused 495 unhandled rejections on v1.9.1. Changes: - Trim actualApiKey at initialization to catch whitespace-only strings - Move new OpenAI() inside try-catch for both new-api and default paths - Add tests for whitespace-only keys and constructor throw scenarios Fixes ELECTRON-6X
Contributor
Code Review:fix(modelBridge): move OpenAI constructor inside try-catch (ELECTRON-6X) (#1797)变更概述本 PR 修复了 Sentry 问题 ELECTRON-6X(495 次事件,v1.9.1 回归)。改动涉及
方案评估结论:✅ 方案合理 双重防御策略(早期 trim + 构造器移入 try-catch)是正确且足够的。两个 OpenAI client 的构建路径(new-api 平台路径 + 默认路径)均已修复,与 IPC bridge 架构边界无关,改动最小化且有针对性。 问题清单🔵 LOW — 第三个测试用例注释与实际执行路径不符文件: 问题代码: // Even if apiKey somehow passes the guard, the constructor error should be caught
const result = await fetchModelList({
base_url: 'https://api.openai.com/v1',
api_key: undefined as unknown as string,
try_fix: false,
});问题说明:传入 修复建议(可选):更新注释以准确反映执行路径: // api_key: undefined is caught by the null guard before reaching the constructor
// This test ensures the guard prevents unhandled rejections for undefined API keys汇总
结论✅ 批准合并 — 无阻塞性问题 修复方案正确,目标明确,测试覆盖充分。唯一的 LOW 问题仅为注释语义偏差,不影响合并。 本报告由本地 CONCLUSION: APPROVED |
Contributor
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1796
Summary
actualApiKeyat initialization to catch whitespace-only strings that pass falsy checksnew OpenAI()constructor inside try-catch for both new-api and default pathsContext
ELECTRON-6X regressed on v1.9.1 (495 events) despite previous fix (PR #1589). The OpenAI SDK v5 constructor throws
Missing credentialsfor whitespace-only API keys, and the constructor was outside the try-catch block, causing unhandled promise rejections.Test plan
bun run test— 8/8 tests pass including 3 new regression testsbunx tsc --noEmit— no type errorsbun run lint:fix— 0 errorsbun run format— formatted