Skip to content

Commit

Permalink
dont re-throw for ps timeout on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 12, 2021
1 parent ab945af commit 7bf7f14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions src/DiffEngine/Process/LinuxOsxProcess.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DiffEngine;
using System.Diagnostics.CodeAnalysis;
using DiffEngine;

static class LinuxOsxProcess
{
Expand Down Expand Up @@ -28,7 +29,11 @@ public static bool TryTerminateProcess(int processId)

public static IEnumerable<ProcessCommand> FindAll()
{
var processList = RunPs();
if (!TryRunPs(out var processList))
{
yield break;
}

using var reader = new StringReader(processList);
string? line;
reader.ReadLine();
Expand Down Expand Up @@ -81,7 +86,7 @@ public static bool TryParse(string line, out ProcessCommand? processCommand)
}
}

static string RunPs()
static bool TryRunPs([NotNullWhen(true)] out string? result)
{
var errorBuilder = new StringBuilder();
var outputBuilder = new StringBuilder();
Expand All @@ -105,21 +110,21 @@ static string RunPs()
process.BeginErrorReadLine();
if (!process.DoubleWaitForExit())
{
var timeoutError = $@"Process timed out. Command line: ps {arguments}.
Output: {outputBuilder}
Error: {errorBuilder}";
throw new(timeoutError);
Trace.WriteLine($@"DiffEngine: Process timed out. Command line: ps {arguments}");
result = null;
return false;
}

if (process.ExitCode == 0)
if (process.ExitCode != 0)
{
return outputBuilder.ToString();
}

var error = $@"Could not execute process. Command line: ps {arguments}.
var error = $@"Could not execute process. Command line: ps {arguments}.
Output: {outputBuilder}
Error: {errorBuilder}";
throw new(error);
throw new(error);
}

result = outputBuilder.ToString();
return true;
}

//To work around https://github.com/dotnet/runtime/issues/27128
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649</NoWarn>
<Version>8.5.1</Version>
<Version>8.5.2</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Testing, Snapshot, Diff, Compare</PackageTags>
<Description>Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.</Description>
Expand Down

0 comments on commit 7bf7f14

Please sign in to comment.