Skip to content
New issue

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

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

Already on GitHub? # to your account

Harden DotNetInfo a bit to handle situations when 'dotnet' doesn't launch properly or return data #879

Merged
merged 1 commit into from
May 31, 2017
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/OmniSharp.Abstractions/Services/DotNetCliService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public DotNetInfo GetInfo(string workingDirectory = null)
return DotNetInfo.Empty;
}

if (process.HasExited)
{
return DotNetInfo.Empty;
}

var lines = new List<string>();
process.OutputDataReceived += (_, e) =>
{
Expand Down
20 changes: 19 additions & 1 deletion src/OmniSharp.Abstractions/Services/DotNetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ private DotNetInfo(string version, string osName, string osVersion, string osPla
{
IsEmpty = false;

Version = SemanticVersion.Parse(version);
Version = SemanticVersion.TryParse(version, out var value)
? value
: null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Version be null or string.Empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, Version is a SemanticVersion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doh I'm slow! lol


OSName = osName;
OSVersion = osVersion;
OSPlatform = osPlatform;
Expand All @@ -36,6 +39,11 @@ private DotNetInfo(string version, string osName, string osVersion, string osPla

public static DotNetInfo Parse(List<string> lines)
{
if (lines == null || lines.Count == 0)
{
return Empty;
}

var version = string.Empty;
var osName = string.Empty;
var osVersion = string.Empty;
Expand Down Expand Up @@ -78,6 +86,16 @@ public static DotNetInfo Parse(List<string> lines)
}
}

if (string.IsNullOrWhiteSpace(version) &&
string.IsNullOrWhiteSpace(osName) &&
string.IsNullOrWhiteSpace(osVersion) &&
string.IsNullOrWhiteSpace(osPlatform) &&
string.IsNullOrWhiteSpace(rid) &&
string.IsNullOrWhiteSpace(basePath))
{
return Empty;
}

return new DotNetInfo(version, osName, osVersion, osPlatform, rid, basePath);
}
}
Expand Down