Skip to content

Commit 70d32df

Browse files
committed
fix(dir): check selenium dir and warn user that the folder does not exist (#17)
closes #11
1 parent 8d6e459 commit 70d32df

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/cmds/start.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from 'fs';
12
import * as minimist from 'minimist';
23
import * as path from 'path';
34
import * as os from 'os';
@@ -51,6 +52,16 @@ function start(options: Options) {
5152
outputDir = path.resolve(Config.getBaseDir(), options[Opt.OUT_DIR].getString());
5253
}
5354
}
55+
56+
try {
57+
// check if folder exists
58+
fs.statSync(outputDir).isDirectory();
59+
} catch (e) {
60+
// if the folder does not exist, quit early.
61+
logger.warn('the out_dir path ' + outputDir + ' does not exist, run webdriver-manager update');
62+
return;
63+
}
64+
5465
let chromeLogs: string = null;
5566
if (options[Opt.CHROME_LOGS].getString()) {
5667
if (path.isAbsolute(options[Opt.CHROME_LOGS].getString())) {

lib/cmds/status.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from 'fs';
12
import * as minimist from 'minimist';
23
import * as path from 'path';
34

@@ -37,6 +38,17 @@ function status(options: Options) {
3738
outputDir = path.resolve(Config.getBaseDir(), options[Opt.OUT_DIR].getString());
3839
}
3940
}
41+
42+
try {
43+
// check if folder exists
44+
fs.statSync(outputDir).isDirectory();
45+
} catch (e) {
46+
// if the folder does not exist, quit early.
47+
logger.warn('the out_dir path ' + outputDir + ' does not exist');
48+
return;
49+
}
50+
51+
4052
let downloadedBinaries = FileManager.downloadedBinaries(outputDir);
4153
// log which binaries have been downloaded
4254
for (let bin in downloadedBinaries) {

lib/files/file_manager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ export class FileManager {
7070
* @param outputDir The directory where binaries are saved
7171
* @returns A list of existing files.
7272
*/
73-
static getExistngFiles(outputDir: string): string[] { return fs.readdirSync(outputDir); }
73+
static getExistngFiles(outputDir: string): string[] {
74+
try {
75+
return fs.readdirSync(outputDir);
76+
} catch (e) {
77+
return [];
78+
}
79+
}
7480

7581
/**
7682
* For the binary, operating system, and system architecture, look through

0 commit comments

Comments
 (0)