Merge pull request #408 from NextTurn/download

Update exception handling for downloads
pull/414/head
Oleg Nenashev 2020-02-16 07:38:26 +01:00 committed by GitHub
commit 0f0ed5f850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 12 deletions

View File

@ -211,7 +211,13 @@ namespace winsw
tasks[i] = download.PerformAsync();
}
Task.WhenAll(tasks);
try
{
Task.WaitAll(tasks);
}
catch (AggregateException e)
{
List<Exception> exceptions = new List<Exception>(e.InnerExceptions.Count);
for (int i = 0; i < tasks.Length; i++)
{
if (tasks[i].IsFaulted)
@ -225,10 +231,13 @@ namespace winsw
// TODO: move this code into the download logic
if (download.FailOnError)
{
throw new IOException(errorMessage, exception);
exceptions.Add(new IOException(errorMessage, exception));
}
}
}
throw new AggregateException(exceptions);
}
#else
foreach (Download download in _descriptor.Downloads)
{