fix: handle VS Code file size limit errors gracefully

- Add error handling for VS Code/Cursor 50MB file size limit
- Catch and handle "Files above X MB cannot be synchronized" errors
- Provide clearer user messages when files exceed display limits
- Ensure file operations complete successfully even if display fails

Fixes #9659
This commit is contained in:
Roo Code 2025-11-28 02:03:53 +00:00
parent 5a6dd58fcb
commit 4a1b29c188
2 changed files with 67 additions and 10 deletions

View file

@ -287,7 +287,26 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
return
} catch (error) {
await handleError("writing file", error as Error)
const err = error as Error
// Check if this is a VS Code file size limit error
if (err?.message?.includes("Files above") && err?.message?.includes("MB")) {
// The file was likely written successfully, but VS Code can't display it
// Provide a more helpful message to the user
await task.say(
"text",
`The file was saved successfully, but it exceeds VS Code's display size limit for extensions. The file operation completed successfully.`,
)
pushToolResult(
formatResponse.toolResult(
`File saved successfully. Note: File exceeds VS Code's display size limit but the operation completed.`,
[],
),
)
await task.diffViewProvider.reset()
return
}
// For other errors, use the standard error handling
await handleError("writing file", err)
await task.diffViewProvider.reset()
return
}

View file

@ -211,7 +211,19 @@ export class DiffViewProvider {
await updatedDocument.save()
}
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true })
try {
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true })
} catch (error: any) {
// Handle VS Code/Cursor file size limit error
if (error?.message?.includes("Files above") && error?.message?.includes("MB")) {
// File was saved successfully but VS Code can't display it due to size limit
// This is not a critical error - the file operation succeeded
console.warn(`File ${absolutePath} exceeds VS Code display size limit but was saved successfully`)
} else {
// Re-throw other errors
throw error
}
}
await this.closeAllDiffViews()
// Getting diagnostics before and after the file edit is a better approach than
@ -436,10 +448,23 @@ export class DiffViewProvider {
await updatedDocument.save()
if (this.documentWasOpen) {
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), {
preview: false,
preserveFocus: true,
})
try {
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), {
preview: false,
preserveFocus: true,
})
} catch (error: any) {
// Handle VS Code/Cursor file size limit error
if (error?.message?.includes("Files above") && error?.message?.includes("MB")) {
// File was reverted successfully but VS Code can't display it due to size limit
console.warn(
`File ${absolutePath} exceeds VS Code display size limit but was reverted successfully`,
)
} else {
// Re-throw other errors
throw error
}
}
}
await this.closeAllDiffViews()
@ -698,10 +723,23 @@ export class DiffViewProvider {
// When openFile is false (PREVENT_FOCUS_DISRUPTION enabled), we only open in memory
if (openFile) {
// Show the document in the editor
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), {
preview: false,
preserveFocus: true,
})
try {
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), {
preview: false,
preserveFocus: true,
})
} catch (error: any) {
// Handle VS Code/Cursor file size limit error
if (error?.message?.includes("Files above") && error?.message?.includes("MB")) {
// File was saved successfully but VS Code can't display it due to size limit
// This is not a critical error - the file operation succeeded
console.warn(`File ${absolutePath} exceeds VS Code display size limit but was saved successfully`)
// Continue with diagnostics check even if we can't display the file
} else {
// Re-throw other errors
throw error
}
}
} else {
// Just open the document in memory to trigger diagnostics without showing it
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(absolutePath))