Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add workspace.fs.stat error handling when files are missing #259

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/expo/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ export class ExpoProjectCache extends MapCacheProvider<ExpoProject> {

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;
}

Expand All @@ -92,11 +97,15 @@ export class ExpoProjectCache extends MapCacheProvider<ExpoProject> {

// 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);
}
}

Expand Down