[Code] handle the case when no workspaces is found during delete (#37758) (#37793)

This commit is contained in:
Mengwei Ding 2019-06-01 14:34:35 -07:00 committed by GitHub
parent 96d0b8a91d
commit 78aa857202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,10 +116,19 @@ export class WorkspaceHandler {
public async listWorkspaceFolders(repoUri: string) {
const workspaceDir = await this.workspaceDir(repoUri);
const isDir = (source: string) => fs.lstatSync(source).isDirectory();
return fs
.readdirSync(workspaceDir)
.map(name => path.join(workspaceDir, name))
.filter(isDir);
try {
return fs
.readdirSync(workspaceDir)
.map(name => path.join(workspaceDir, name))
.filter(isDir);
} catch (error) {
if (error.code === 'ENOENT') {
this.log.debug('Cannot find workspace dirs');
return [];
} else {
throw error;
}
}
}
public async clearWorkspace(repoUri: string) {