Skip to content

Commit db095b7

Browse files
committed
fix: handle empty workspaceFolders array to prevent path type error
- Fix getWorkspacePath() in src/utils/path.ts to check array length before accessing - Fix getCwd() in FileContextTracker to check array length before accessing - Fix cwd assignment in claude-code/run.ts to check array length before accessing This prevents 'path argument must be of type string. Received an instance of Array' error when workspaceFolders is an empty array. Fixes #7695
1 parent 90e7d09 commit db095b7

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/core/context-tracking/FileContextTracker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export class FileContextTracker {
3737

3838
// Gets the current working directory or returns undefined if it cannot be determined
3939
private getCwd(): string | undefined {
40-
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
40+
// Ensure we handle empty arrays properly - check length before accessing
41+
const workspaceFolders = vscode.workspace.workspaceFolders
42+
const cwd = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : undefined
4143
if (!cwd) {
4244
console.info("No workspace folder available - cannot determine current working directory")
4345
}

src/integrations/claude-code/run.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { CLAUDE_CODE_DEFAULT_MAX_OUTPUT_TOKENS } from "@roo-code/types"
77
import * as os from "os"
88
import { t } from "../../i18n"
99

10-
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
10+
// Ensure we handle empty arrays properly - check length before accessing
11+
const workspaceFolders = vscode.workspace.workspaceFolders
12+
const cwd = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : undefined
1113

1214
// Claude Code installation URL - can be easily updated if needed
1315
const CLAUDE_CODE_INSTALLATION_URL = "https://docs.anthropic.com/en/docs/claude-code/setup"

src/utils/path.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export const toRelativePath = (filePath: string, cwd: string) => {
107107
}
108108

109109
export const getWorkspacePath = (defaultCwdPath = "") => {
110-
const cwdPath = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || defaultCwdPath
110+
// Ensure we handle empty arrays properly - check length before mapping
111+
const workspaceFolders = vscode.workspace.workspaceFolders
112+
const cwdPath = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : defaultCwdPath
111113
const currentFileUri = vscode.window.activeTextEditor?.document.uri
112114
if (currentFileUri) {
113115
const workspaceFolder = vscode.workspace.getWorkspaceFolder(currentFileUri)

0 commit comments

Comments
 (0)