Skip to content

Commit

Permalink
Merge pull request #32 from AElfProject/fix/build-error
Browse files Browse the repository at this point in the history
Adding exitcode for better error handling
  • Loading branch information
AelfHarsh authored Sep 25, 2024
2 parents 1a1b146 + d719259 commit 2bf3723
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions PlaygroundService/Utilities/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ public class ProcessHelper

try
{
var result = await RunProcess("dotnet", command, projectDirectory);
return (true, result);
// Run the process and capture the output
var (exitCode, result) = await RunProcess("dotnet", command, projectDirectory);

// Return true if exit code is 0, otherwise false with the captured output
return (exitCode == 0, result);
}
catch (Exception e)
{
return (false, e.Message);
}
}

private static async Task<string> RunProcess(string fileName, string arguments, string workingDirectory = null)

private static async Task<(int, string)> RunProcess(string fileName, string arguments, string workingDirectory = null)

Check warning on line 40 in PlaygroundService/Utilities/ProcessHelper.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var startInfo = new ProcessStartInfo
{
Expand Down Expand Up @@ -62,12 +66,7 @@ private static async Task<string> RunProcess(string fileName, string arguments,
await process.WaitForExitAsync();

var allOutput = output.ToString() + error.ToString(); // Combine stdout and stderr
if (process.ExitCode != 0)
{
return $"Process exited with code {process.ExitCode}. Details: {allOutput}";
}

return allOutput;
return (process.ExitCode, allOutput); // Return exit code and output
}

}

0 comments on commit 2bf3723

Please sign in to comment.