Skip to content

Commit 35f3a6f

Browse files
committed
Added exception handling when reading directories
1 parent 991f483 commit 35f3a6f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/languageservice/services/gitlabciUtils.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,21 @@ function registerFile(path: string): void {
196196
}
197197

198198
function registerWorkspaceFiles(path: string): void {
199-
const files = readdirSync(path);
200-
for (const file of files) {
201-
const filePath = path + '/' + file;
202-
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
203-
registerFile(filePath);
204-
} else if (statSync(filePath).isDirectory()) {
205-
registerWorkspaceFiles(filePath);
199+
try {
200+
const files = readdirSync(path);
201+
for (const file of files) {
202+
const filePath = path + '/' + file;
203+
const stats = statSync(filePath);
204+
205+
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
206+
registerFile(filePath);
207+
} else if (stats.isDirectory()) {
208+
registerWorkspaceFiles(filePath);
209+
}
206210
}
211+
} catch (e) {
212+
console.warn('Error reading directory: ' + path + ', ignoring it');
213+
return;
207214
}
208215
}
209216

0 commit comments

Comments
 (0)