Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 34fe5c6

Browse files
committed
Fix Successful state of process task
If we're running tasks directly with RunWithReturn, the Task object never gets go a completion state, which means Successful would always return false.
1 parent 192d515 commit 34fe5c6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/GitHub.Api/Tasks/ProcessTask.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class ProcessTask<T> : TaskBase<T>, IProcessTask<T>
213213
{
214214
private IOutputProcessor<T> outputProcessor;
215215
private ProcessWrapper wrapper;
216+
private bool finished = false;
216217

217218
public event Action<string> OnErrorData;
218219
public event Action<IProcess> OnStartProcess;
@@ -302,6 +303,7 @@ public override T RunWithReturn(bool success)
302303
RaiseOnStart,
303304
() =>
304305
{
306+
finished = true;
305307
try
306308
{
307309
if (outputProcessor != null)
@@ -350,7 +352,7 @@ public override string ToString()
350352

351353
public Process Process { get; set; }
352354
public int ProcessId { get { return Process.Id; } }
353-
public override bool Successful { get { return !taskFailed && Task.Status == TaskStatus.RanToCompletion && Process.ExitCode == 0; } }
355+
public override bool Successful { get { return finished && ((!taskFailed && Process.ExitCode == 0) || (taskFailed && exceptionWasHandled)); } }
354356
public StreamWriter StandardInput { get { return wrapper?.Input; } }
355357
public virtual string ProcessName { get; protected set; }
356358
public virtual string ProcessArguments { get; }

src/GitHub.Api/Tasks/TaskBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public override string ToString()
491491
return $"{Task?.Id ?? -1} {Name} {GetType()}";
492492
}
493493

494-
public virtual bool Successful { get { return !taskFailed || exceptionWasHandled; /*Task.Status == TaskStatus.RanToCompletion && Task.Status != TaskStatus.Faulted;*/ } }
494+
public virtual bool Successful { get { return !taskFailed || exceptionWasHandled; } }
495495
public string Errors { get; protected set; }
496496
public Task Task { get; protected set; }
497497
public bool IsCompleted { get { return hasRun; /*(Task as IAsyncResult).IsCompleted;*/ } }

0 commit comments

Comments
 (0)