From 03d0ccc4d72083634ebc132d431db6186873de83 Mon Sep 17 00:00:00 2001 From: Next Turn <45985406+nxtn@users.noreply.github.com> Date: Mon, 9 Aug 2021 13:10:41 +0800 Subject: [PATCH] Fix download exceptions when ignoring errors --- src/WinSW.Core/Download.cs | 8 ++++++-- src/WinSW.Core/WrapperService.cs | 27 +-------------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/WinSW.Core/Download.cs b/src/WinSW.Core/Download.cs index f1eb799..fa6c8a7 100644 --- a/src/WinSW.Core/Download.cs +++ b/src/WinSW.Core/Download.cs @@ -193,10 +193,14 @@ namespace WinSW if (supportsIfModifiedSince && ((HttpWebResponse?)e.Response)?.StatusCode == HttpStatusCode.NotModified) { Logger.Info($"Skipped downloading unmodified resource '{this.From}'"); + return; } - else + + string errorMessage = $"Failed to download {this.From} to {this.To}"; + Logger.Error(errorMessage, e); + if (this.FailOnError) { - throw; + throw new IOException(errorMessage, e); } } } diff --git a/src/WinSW.Core/WrapperService.cs b/src/WinSW.Core/WrapperService.cs index 3bb8076..7a97721 100644 --- a/src/WinSW.Core/WrapperService.cs +++ b/src/WinSW.Core/WrapperService.cs @@ -272,32 +272,7 @@ namespace WinSW tasks[i] = download.PerformAsync(); } - try - { - Task.WaitAll(tasks); - } - catch (AggregateException e) - { - var exceptions = new List(e.InnerExceptions.Count); - for (int i = 0; i < tasks.Length; i++) - { - if (tasks[i].IsFaulted) - { - var download = downloads[i]; - string errorMessage = $"Failed to download {download.From} to {download.To}"; - var exception = tasks[i].Exception!; - Log.Error(errorMessage, exception); - - // TODO: move this code into the download logic - if (download.FailOnError) - { - exceptions.Add(new IOException(errorMessage, exception)); - } - } - } - - throw new AggregateException(exceptions); - } + Task.WaitAll(tasks); var sharedDirectories = this.config.SharedDirectories; if (sharedDirectories.Count > 0)