Skip to content

Commit

Permalink
Improve error messaging when locating tools fails
Browse files Browse the repository at this point in the history
The subprocess run of `dotnet list package` didn't have exit code
checking, so it'd fail silently if anything inside dotnet fell over.
For better experience, check the exit code of dotnet and throw if it's
not zero, additionally appending stdout from the command
for convenience.

I hit this locally in testing other changes. Cause of failure was
incorrect working directory spec.
bdach committed Feb 27, 2024
1 parent d56264e commit 3555d5c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
@@ -678,13 +678,17 @@ private static string getToolPath(string packageName, string toolExecutable)
{
var process = Process.Start(new ProcessStartInfo("dotnet", "list osu.Desktop.Deploy.csproj package")
{
RedirectStandardOutput = true
RedirectStandardOutput = true,
RedirectStandardError = true,
});

Debug.Assert(process != null);

process.WaitForExit();

if (process.ExitCode != 0)
throw new InvalidOperationException($"Could not locate tool {toolExecutable}!\nStandard error: {process.StandardError.ReadToEnd()}");

string output = process.StandardOutput.ReadToEnd();

var match = Regex.Matches(output, $@"(?m){packageName.Replace(".", "\\.")}.*\s(\d{{1,3}}\.\d{{1,3}}\.\d.*?)$");

0 comments on commit 3555d5c

Please sign in to comment.