Skip to content

Commit 90c17fc

Browse files
committed
Validate directory path and workspace root existence before calculating selected tokens to prevent errors
1 parent 8d23bdf commit 90c17fc

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/vscode/src/context/providers/workspace-provider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,23 @@ export class WorkspaceProvider
744744
private async _calculate_directory_selected_tokens(
745745
dir_path: string
746746
): Promise<number> {
747+
if (!dir_path) {
748+
return 0
749+
}
747750
if (this.directory_selected_token_counts.has(dir_path)) {
748751
return this.directory_selected_token_counts.get(dir_path)!
749752
}
750753

751754
let selected_tokens = 0
752755
try {
753756
const workspace_root = this.get_workspace_root_for_file(dir_path)
754-
if (!workspace_root) return 0
757+
if (!workspace_root || workspace_root === '') {
758+
Logger.warn({
759+
function_name: '_calculate_directory_selected_tokens',
760+
message: `No workspace root found for directory ${dir_path}`
761+
})
762+
return 0
763+
}
755764

756765
const relative_dir_path = path.relative(workspace_root, dir_path)
757766
if (this.is_excluded(relative_dir_path)) {

0 commit comments

Comments
 (0)