mirror of https://github.com/winsw/winsw
Fix download exceptions when ignoring errors (#854)
parent
20846238ea
commit
9bfc034807
|
@ -231,10 +231,14 @@ namespace WinSW
|
||||||
if (supportsIfModifiedSince && ((HttpWebResponse?)e.Response)?.StatusCode == HttpStatusCode.NotModified)
|
if (supportsIfModifiedSince && ((HttpWebResponse?)e.Response)?.StatusCode == HttpStatusCode.NotModified)
|
||||||
{
|
{
|
||||||
Logger.Info($"Skipped downloading unmodified resource '{this.From}'");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,10 +215,11 @@ namespace winswTests
|
||||||
await this.TestClientServerAsync(
|
await this.TestClientServerAsync(
|
||||||
async (source, dest) =>
|
async (source, dest) =>
|
||||||
{
|
{
|
||||||
var exception = await AsyncAssert.ThrowsAsync<WebException>(
|
var exception = await AsyncAssert.ThrowsAsync<IOException>(
|
||||||
async () => await new Download(source, dest).PerformAsync());
|
async () => await new Download(source, dest, true).PerformAsync());
|
||||||
|
|
||||||
Assert.That(exception.Status, Is.EqualTo(WebExceptionStatus.ProtocolError));
|
var inner = (WebException)exception.InnerException;
|
||||||
|
Assert.That(inner.Status, Is.EqualTo(WebExceptionStatus.ProtocolError));
|
||||||
},
|
},
|
||||||
context =>
|
context =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,9 +21,9 @@ namespace WinSW
|
||||||
public class WrapperService : ServiceBase, IEventLogger
|
public class WrapperService : ServiceBase, IEventLogger
|
||||||
{
|
{
|
||||||
private readonly Process process = new();
|
private readonly Process process = new();
|
||||||
|
|
||||||
private readonly IServiceConfig config;
|
private readonly IServiceConfig config;
|
||||||
|
|
||||||
private Dictionary<string, string>? envs;
|
private Dictionary<string, string>? envs;
|
||||||
|
|
||||||
internal WinSWExtensionManager ExtensionManager { get; private set; }
|
internal WinSWExtensionManager ExtensionManager { get; private set; }
|
||||||
|
@ -246,57 +246,14 @@ namespace WinSW
|
||||||
tasks[i] = download.PerformAsync();
|
tasks[i] = download.PerformAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
Task.WaitAll(tasks);
|
||||||
{
|
|
||||||
Task.WaitAll(tasks);
|
|
||||||
}
|
|
||||||
catch (AggregateException e)
|
|
||||||
{
|
|
||||||
var exceptions = new List<Exception>(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!;
|
|
||||||
this.LogEvent($"{errorMessage}. {exception.Message}");
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
foreach (var download in this.config.Downloads)
|
foreach (var download in this.config.Downloads)
|
||||||
{
|
{
|
||||||
string downloadMessage = $"Downloading: {download.From} to {download.To}. failOnError={download.FailOnError.ToString()}";
|
string downloadMessage = $"Downloading: {download.From} to {download.To}. failOnError={download.FailOnError.ToString()}";
|
||||||
this.LogEvent(downloadMessage);
|
this.LogEvent(downloadMessage);
|
||||||
Log.Info(downloadMessage);
|
Log.Info(downloadMessage);
|
||||||
try
|
download.Perform();
|
||||||
{
|
|
||||||
download.Perform();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
string errorMessage = $"Failed to download {download.From} to {download.To}";
|
|
||||||
this.LogEvent($"{errorMessage}. {e.Message}");
|
|
||||||
Log.Error(errorMessage, e);
|
|
||||||
|
|
||||||
// TODO: move this code into the download logic
|
|
||||||
if (download.FailOnError)
|
|
||||||
{
|
|
||||||
throw new IOException(errorMessage, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Else just keep going
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue