Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 056b05d

Browse files
Merge pull request #123 from skbkontur/feature/dont-write-error-autoupdate
dont write error in console in autoupdate
2 parents a87fbea + 3729284 commit 056b05d

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

Commands/SelfUpdate.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Net;
66
using Common;
7+
using Microsoft.Build.Logging;
78
using Microsoft.Extensions.Logging;
89

910
namespace Commands
@@ -35,11 +36,17 @@ public static void UpdateIfOld()
3536
if (diff <= TimeSpan.FromHours(5))
3637
return;
3738
isAutoUpdate = true;
38-
new SelfUpdate().Run(new[] {"self-update"});
39+
var exitCode = new SelfUpdate().Run(new[] {"self-update"});
40+
if (exitCode != 0)
41+
{
42+
Log.LogError("Auto update cement failed. 'self-update' exited with code '{Code}'", exitCode);
43+
ConsoleWriter.WriteWarning("Auto update failed. Check previous warnings for details");
44+
}
3945
}
4046
catch (Exception exception)
4147
{
42-
Log.LogError("Fail to auto update", exception);
48+
Log.LogError("Auto update failed, error: '{Exception}'", exception);
49+
ConsoleWriter.WriteWarning("Auto update failed. Check logs for details");
4350
}
4451
}
4552

@@ -187,21 +194,21 @@ private bool UpdateBinaries(ICementUpdater updater, string oldHash, string newHa
187194
Log.LogDebug(okMessage);
188195
return true;
189196
}
190-
catch (WebException ex)
197+
catch (WebException webException)
191198
{
192-
Log.LogError("Fail self-update", ex);
199+
Log.LogError("Fail self-update, exception: '{Exception}'", webException);
193200

194-
if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
201+
if (webException.Status == WebExceptionStatus.ProtocolError && webException.Response != null)
195202
{
196-
var resp = (HttpWebResponse) ex.Response;
203+
var resp = (HttpWebResponse) webException.Response;
197204
if (resp.StatusCode == HttpStatusCode.NotFound) // HTTP 404
198205
{
199-
ConsoleWriter.WriteError($"Failed to look for updates on branch {branch}. Server responsed 404 ({updater.GetName()})");
206+
ConsoleWriter.WriteWarning($"Failed to look for updates on branch {branch}. Server replied 404 ({updater.GetName()})");
200207
return false;
201208
}
202209
}
203210

204-
ConsoleWriter.WriteError($"Failed to look for updates on branch {branch}. {ex.Message} ({updater.GetName()})");
211+
ConsoleWriter.WriteWarning($"Failed to look for updates on branch {branch}. {webException.Message} ({updater.GetName()})");
205212
return false;
206213
}
207214
}

Common/CementFromGitHubUpdater.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Newtonsoft.Json;
22
using System.Collections.Generic;
33
using System.Net;
4-
using Common.Extensions;
54
using Microsoft.Extensions.Logging;
65

76
namespace Common
@@ -31,19 +30,19 @@ public string GetNewCommitHash()
3130
var parts = downloadUri.Split('/', '.');
3231
return parts[parts.Length - 2];
3332
}
34-
catch (WebException ex)
33+
catch (WebException webException)
3534
{
36-
log.LogError("Fail self-update ", ex);
37-
if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
35+
log.LogError("Fail self-update, exception: '{Exception}' ", webException);
36+
if (webException.Status == WebExceptionStatus.ProtocolError && webException.Response != null)
3837
{
39-
var resp = (HttpWebResponse) ex.Response;
40-
if (resp.StatusCode == HttpStatusCode.NotFound) // HTTP 404
38+
var response = (HttpWebResponse) webException.Response;
39+
if (response.StatusCode == HttpStatusCode.NotFound) // HTTP 404
4140
{
42-
ConsoleWriter.WriteError("Failed to look for updates on github. Server responsed 404");
41+
ConsoleWriter.WriteWarning("Failed to look for updates on github. Server replied 404");
4342
return null;
4443
}
4544
}
46-
ConsoleWriter.WriteError("Failed to look for updates on github: " + ex.Message);
45+
ConsoleWriter.WriteWarning("Failed to look for updates on github: " + webException.Message);
4746
return null;
4847
}
4948
}

Common/CementFromServerUpdater.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ public string GetNewCommitHash()
2323
var webClient = new WebClient();
2424
try
2525
{
26-
var infoModel = JsonConvert.DeserializeObject<InfoResponseModel>(webClient.DownloadString($"{CementSettings.Get().CementServer}/api/v1/cement/info/head/" + branch));
27-
return infoModel?.CommitHash;
26+
var info = JsonConvert.DeserializeObject<InfoResponseModel>(webClient.DownloadString($"{CementSettings.Get().CementServer}/api/v1/cement/info/head/" + branch));
27+
return info?.CommitHash;
2828
}
29-
catch (WebException ex)
29+
catch (WebException webException)
3030
{
31-
log.LogError("Fail self-update ", ex);
32-
if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
31+
log.LogError("Fail self-update, exception: '{Exception}'", webException);
32+
if (webException.Status == WebExceptionStatus.ProtocolError && webException.Response != null)
3333
{
34-
var resp = (HttpWebResponse) ex.Response;
35-
if (resp.StatusCode == HttpStatusCode.NotFound) // HTTP 404
34+
var response = (HttpWebResponse) webException.Response;
35+
if (response.StatusCode == HttpStatusCode.NotFound) // HTTP 404
3636
{
37-
ConsoleWriter.WriteError("Failed to look for updates on branch " + branch + ". Server responsed 404");
37+
ConsoleWriter.WriteWarning("Failed to look for updates on branch " + branch + ". Server replied 404");
3838
return null;
3939
}
4040
}
41-
ConsoleWriter.WriteError("Failed to look for updates on branch " + branch + ": " + ex.Message);
41+
ConsoleWriter.WriteWarning("Failed to look for updates on branch " + branch + ": " + webException.Message);
4242
return null;
4343
}
4444
}

0 commit comments

Comments
 (0)