Skip to content

Commit 0cd79df

Browse files
Checking paths don't throw exception
1 parent b144c5d commit 0cd79df

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Components/Environment.fs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ module Environment =
1717
if isWin then a + @"\" + b
1818
else a + "/" + b
1919

20-
let private dirExists dir = fs.statSync(dir).isDirectory()
20+
let private dirExists dir =
21+
try
22+
fs.statSync(dir).isDirectory()
23+
with
24+
| _ -> false
2125

22-
let private fileExists file = fs.statSync(file).isFile()
26+
let private fileExists file =
27+
try
28+
fs.statSync(file).isFile()
29+
with
30+
| _ -> false
2331

2432
let private getOrElse defaultValue option =
2533
match option with
@@ -49,25 +57,25 @@ module Environment =
4957

5058
let private getListDirectoriesToSearchForTools () =
5159
if isWin then
52-
[ getToolsPathFromConfiguration (); getToolsPathWindows () ]
60+
[ getToolsPathFromConfiguration (); getToolsPathWindows () ]
5361
else
5462
[ getToolsPathFromConfiguration () ]
5563
|> List.choose id
56-
64+
5765
let private findFirstValidFilePath exeName directoryList =
5866
directoryList
5967
|> List.map (fun v -> v </> exeName)
60-
|> List.tryFind fileExists
68+
|> List.tryFind fileExists
6169

6270
let private getFsiFilePath () =
6371
if isWin then
6472
let cfg = workspace.getConfiguration ()
6573
let fsiPath = cfg.get("FSharp.fsiFilePath", "")
66-
if fsiPath = "" then "FsiAnyCpu.exe" else fsiPath
74+
if fsiPath = "" then "FsiAnyCpu.exe" else fsiPath
6775
else "fsharpi"
6876

6977
let fsi =
70-
let fileName = getFsiFilePath ()
78+
let fileName = getFsiFilePath ()
7179
let dirs = getListDirectoriesToSearchForTools ()
7280
match findFirstValidFilePath fileName dirs with
7381
| None -> fileName

0 commit comments

Comments
 (0)