修复: 添加工作区验证以防止.openmcp目录创建错误

- 在getWorkspaceConnectionConfigPath()中添加工作区路径验证
- 在getWorkspaceConnectionConfig()中添加工作区路径验证
- 当没有找到工作区时抛出描述性错误
- 解决VSCode扩展尝试创建.openmcp目录时的ENOENT错误
This commit is contained in:
Meghan Morrow 2025-06-19 10:55:06 +08:00
parent 777a17bb99
commit 8446cf07dc

View File

@ -95,6 +95,9 @@ export function getConnectionConfig() {
*/ */
export function getWorkspaceConnectionConfigPath() { export function getWorkspaceConnectionConfigPath() {
const workspace = getWorkspacePath(); const workspace = getWorkspacePath();
if (!workspace) {
throw new Error('No workspace found. Please open a folder in VSCode first.');
}
const configDir = fspath.join(workspace, '.openmcp'); const configDir = fspath.join(workspace, '.openmcp');
if (!fs.existsSync(configDir)) { if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true }); // 递归创建目录 fs.mkdirSync(configDir, { recursive: true }); // 递归创建目录
@ -113,6 +116,9 @@ export function getWorkspaceConnectionConfig() {
} }
const workspace = getWorkspacePath(); const workspace = getWorkspacePath();
if (!workspace) {
throw new Error('No workspace found. Please open a folder in VSCode first.');
}
const configDir = fspath.join(workspace, '.openmcp'); const configDir = fspath.join(workspace, '.openmcp');
const connectionConfig = fspath.join(configDir, CONNECTION_CONFIG_NAME); const connectionConfig = fspath.join(configDir, CONNECTION_CONFIG_NAME);