Skip to content

Commit b595056

Browse files
committed
Improve error handling for 'isOnPath'
isOnPath calls existsSync, which was not handling ENOTDIR. This can arise if a portion of a path is not a directory, such as /dir1/dir2/<executable>/foo/bar. existsSync should return false in these cases. Additionally, this adds a try/catch to isOnPath that should catch all other errors from existsSync and treat them as basic failures for that particular path segment.
1 parent 019520c commit b595056

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csharp",
33
"publisher": "ms-vscode",
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"description": "C# for Visual Studio Code (powered by OmniSharp).",
66
"displayName": "C#",
77
"author": "Microsoft Corporation",

src/coreclr-debug/main.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,29 @@ function isOnPath(command : string) : boolean {
200200
return false;
201201
}
202202
let fileName = command;
203-
let seperatorChar = ':';
204203
if (process.platform == 'win32') {
205204
// on Windows, add a '.exe', and the path is semi-colon seperatode
206205
fileName = fileName + ".exe";
207-
seperatorChar = ';';
208206
}
209-
210-
let pathSegments: string[] = pathValue.split(seperatorChar);
207+
208+
let pathSegments: string[] = pathValue.split(path.delimiter);
211209
for (let segment of pathSegments) {
212210
if (segment.length === 0 || !path.isAbsolute(segment)) {
213211
continue;
214212
}
215-
213+
216214
const segmentPath = path.join(segment, fileName);
217-
if (CoreClrDebugUtil.existsSync(segmentPath)) {
218-
return true;
215+
216+
try {
217+
if (CoreClrDebugUtil.existsSync(segmentPath)) {
218+
return true;
219+
}
220+
} catch (err) {
221+
// any error from existsSync can be treated as the command not being on the path
222+
continue;
219223
}
220224
}
221-
225+
222226
return false;
223227
}
224228

src/coreclr-debug/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default class CoreClrDebugUtil
8383
fs.accessSync(path, fs.F_OK);
8484
return true;
8585
} catch (err) {
86-
if (err.code === 'ENOENT') {
86+
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
8787
return false;
8888
} else {
8989
throw Error(err.code);

0 commit comments

Comments
 (0)