From a5c6199e11909ea2003e197563fab69a2ee2f245 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 13 Mar 2024 13:09:23 +0100 Subject: [PATCH] fix: add `workspace.fs.stat` error handling when files are missing (#259) --- src/expo/project.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/expo/project.ts b/src/expo/project.ts index 51fbb16..3b4b603 100644 --- a/src/expo/project.ts +++ b/src/expo/project.ts @@ -76,9 +76,14 @@ export class ExpoProjectCache extends MapCacheProvider { const packagePath = vscode.Uri.joinPath(projectPath, 'package.json'); - // Ensure the project has a `package.json` file - const packageInfo = await vscode.workspace.fs.stat(packagePath); - if (packageInfo.type !== vscode.FileType.File) { + try { + // Ensure the project has a `package.json` file + const packageInfo = await vscode.workspace.fs.stat(packagePath); + if (packageInfo.type !== vscode.FileType.File) { + return undefined; + } + } catch (error) { + log('Failed to load Expo project "package.json": %s', error.message); return undefined; } @@ -92,11 +97,15 @@ export class ExpoProjectCache extends MapCacheProvider { // Load the `app.json` or `app.config.json` file, if available for (const appFileName of ['app.json', 'app.config.json']) { - const filePath = vscode.Uri.joinPath(projectPath, appFileName); - const fileStat = await vscode.workspace.fs.stat(filePath); - if (fileStat.type === vscode.FileType.File) { - project.setManifest(await readWorkspaceFile(filePath)); - break; + try { + const filePath = vscode.Uri.joinPath(projectPath, appFileName); + const fileStat = await vscode.workspace.fs.stat(filePath); + if (fileStat.type === vscode.FileType.File) { + project.setManifest(await readWorkspaceFile(filePath)); + break; + } + } catch (error) { + log('Failed to load Expo project "%s": %s', appFileName, error.message); } }