fix: handle empty workspace folders array to prevent path type errors

- Replace .at(0) with safe array access using length checks
- Fixes "path argument must be of type string" error when workspace is empty
- Addresses regression introduced between v3.25.17 and v3.26.7

Fixes #7695
This commit is contained in:
Roo Code 2025-09-05 07:13:10 +00:00
parent db095b7feb
commit f276e68133

View file

@ -86,7 +86,10 @@ const createServerTypeSchema = () => {
type: z.enum(["stdio"]).optional(),
command: z.string().min(1, "Command cannot be empty"),
args: z.array(z.string()).optional(),
cwd: z.string().default(() => vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath ?? process.cwd()),
cwd: z.string().default(() => {
const workspaceFolders = vscode.workspace.workspaceFolders
return workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : process.cwd()
}),
env: z.record(z.string()).optional(),
// Ensure no SSE fields are present
url: z.undefined().optional(),