mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
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
This commit is contained in:
parent
90e7d09596
commit
db095b7feb
3 changed files with 9 additions and 3 deletions
|
|
@ -37,7 +37,9 @@ export class FileContextTracker {
|
|||
|
||||
// Gets the current working directory or returns undefined if it cannot be determined
|
||||
private getCwd(): string | undefined {
|
||||
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
|
||||
// Ensure we handle empty arrays properly - check length before accessing
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders
|
||||
const cwd = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : undefined
|
||||
if (!cwd) {
|
||||
console.info("No workspace folder available - cannot determine current working directory")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import { CLAUDE_CODE_DEFAULT_MAX_OUTPUT_TOKENS } from "@roo-code/types"
|
|||
import * as os from "os"
|
||||
import { t } from "../../i18n"
|
||||
|
||||
const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0)
|
||||
// Ensure we handle empty arrays properly - check length before accessing
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders
|
||||
const cwd = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : undefined
|
||||
|
||||
// Claude Code installation URL - can be easily updated if needed
|
||||
const CLAUDE_CODE_INSTALLATION_URL = "https://docs.anthropic.com/en/docs/claude-code/setup"
|
||||
|
|
|
|||
|
|
@ -107,7 +107,9 @@ export const toRelativePath = (filePath: string, cwd: string) => {
|
|||
}
|
||||
|
||||
export const getWorkspacePath = (defaultCwdPath = "") => {
|
||||
const cwdPath = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || defaultCwdPath
|
||||
// Ensure we handle empty arrays properly - check length before mapping
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders
|
||||
const cwdPath = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : defaultCwdPath
|
||||
const currentFileUri = vscode.window.activeTextEditor?.document.uri
|
||||
if (currentFileUri) {
|
||||
const workspaceFolder = vscode.workspace.getWorkspaceFolder(currentFileUri)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue