Skip to content

Commit af86d53

Browse files
committed
retain original TimeoutException
1 parent a4be1a9 commit af86d53

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Microsoft.ComponentDetection.Common/AsyncExecution.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public static async Task<T> ExecuteWithTimeoutAsync<T>(Func<Task<T>> toExecute,
2828
{
2929
return await work.WaitAsync(timeout, cancellationToken);
3030
}
31-
catch (TimeoutException)
31+
catch (TimeoutException ex)
3232
{
33-
throw new TimeoutException($"The execution did not complete in the allotted time ({timeout.TotalSeconds} seconds) and has been terminated prior to completion");
33+
throw new TimeoutException($"The execution did not complete in the allotted time ({timeout.TotalSeconds} seconds) and has been terminated prior to completion", ex);
3434
}
3535
}
3636

@@ -43,7 +43,6 @@ public static async Task<T> ExecuteWithTimeoutAsync<T>(Func<Task<T>> toExecute,
4343
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
4444
/// <exception cref="ArgumentNullException">Thrown when <paramref name="toExecute"/> is null.</exception>
4545
/// <exception cref="TimeoutException">Thrown when the execution does not complete within the timeout.</exception>
46-
/// <remarks>NOTE: If the function to execute does not respect cancellation tokens, it may continue running in the background after a timeout.</remarks>
4746
public static async Task ExecuteVoidWithTimeoutAsync(Action toExecute, TimeSpan timeout, CancellationToken cancellationToken = default)
4847
{
4948
ArgumentNullException.ThrowIfNull(toExecute);
@@ -54,9 +53,9 @@ public static async Task ExecuteVoidWithTimeoutAsync(Action toExecute, TimeSpan
5453
{
5554
await work.WaitAsync(timeout, cancellationToken);
5655
}
57-
catch (TimeoutException)
56+
catch (TimeoutException ex)
5857
{
59-
throw new TimeoutException($"The execution did not complete in the allotted time ({timeout.TotalSeconds} seconds) and has been terminated prior to completion");
58+
throw new TimeoutException($"The execution did not complete in the allotted time ({timeout.TotalSeconds} seconds) and has been terminated prior to completion", ex);
6059
}
6160
}
6261
}

0 commit comments

Comments
 (0)