Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add clearer message on failure #210

Merged
merged 1 commit into from
Sep 2, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,6 @@ msbuild.binlog

.fake
.ionide
obj2
obj2

.idea/
21 changes: 14 additions & 7 deletions src/Ionide.ProjInfo/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module SdkDiscovery =
Path: DirectoryInfo
}

let internal execDotnet (cwd: DirectoryInfo) (binaryFullPath: FileInfo) args =
let internal execDotnet (failOnError: bool) (cwd: DirectoryInfo) (binaryFullPath: FileInfo) args =
let info = ProcessStartInfo()
info.WorkingDirectory <- cwd.FullName
info.FileName <- binaryFullPath.FullName
Expand All @@ -45,8 +45,15 @@ module SdkDiscovery =
|> Seq.toArray

p.WaitForExit()
output

if p.ExitCode = 0 then
output
elif failOnError then
let output = output |> String.concat "\n"
failwith $"`{binaryFullPath.FullName} {args}` failed with exit code %i{p.ExitCode}. Output: %s{output}"
else
// for the legacy VS flow, whose behaviour is harder to test, we maintain compatibility with how proj-info
// used to work before the above error handling was added
output

let private (|SemVer|_|) version =
match SemanticVersioning.Version.TryParse version with
Expand Down Expand Up @@ -75,7 +82,7 @@ module SdkDiscovery =
/// Given the DOTNET_ROOT, that is the directory where the `dotnet` binary is present and the sdk/runtimes/etc are,
/// enumerates the available runtimes in descending version order
let runtimes (dotnetBinaryPath: FileInfo) : DotnetRuntimeInfo[] =
execDotnet dotnetBinaryPath.Directory dotnetBinaryPath [ "--list-runtimes" ]
execDotnet true dotnetBinaryPath.Directory dotnetBinaryPath [ "--list-runtimes" ]
|> Seq.choose (fun line ->
match line with
| RuntimeParts(runtimeName, SemVer version, SdkOutputDirectory path) ->
Expand All @@ -98,7 +105,7 @@ module SdkDiscovery =
/// Given the DOTNET_sROOT, that is the directory where the `dotnet` binary is present and the sdk/runtimes/etc are,
/// enumerates the available SDKs in descending version order
let sdks (dotnetBinaryPath: FileInfo) : DotnetSdkInfo[] =
execDotnet dotnetBinaryPath.Directory dotnetBinaryPath [ "--list-sdks" ]
execDotnet true dotnetBinaryPath.Directory dotnetBinaryPath [ "--list-sdks" ]
|> Seq.choose (fun line ->
match line with
| SdkParts(SemVer sdkVersion, SdkOutputDirectory path) ->
Expand All @@ -115,7 +122,7 @@ module SdkDiscovery =
/// performs a `dotnet --version` command at the given directory to get the version of the
/// SDK active at that location.
let versionAt (cwd: DirectoryInfo) (dotnetBinaryPath: FileInfo) =
execDotnet cwd dotnetBinaryPath [ "--version" ]
execDotnet true cwd dotnetBinaryPath [ "--version" ]
|> Seq.head
|> function
| version ->
Expand Down Expand Up @@ -159,7 +166,7 @@ module LegacyFrameworkDiscovery =
failwith $"\"{vsWhereExe}\" does not exist. It is a expected to be present in '<ProgramFilesX86>/Microsoft Visual Studio/Installer' when resolving the MsBuild for legacy projects."

let msbuildExe =
SdkDiscovery.execDotnet vsWhereDir vsWhereExe [
SdkDiscovery.execDotnet false vsWhereDir vsWhereExe [
"-find"
"MSBuild\**\Bin\MSBuild.exe"
]
Expand Down
Loading