From a77dc4f28a371eca49089c817d266c652c598a89 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Wed, 14 Feb 2024 15:51:30 -0600 Subject: [PATCH] Show repo ETag and parsing errors in Failed Downloads --- Core/Net/Net.cs | 17 ++++++++--- Core/Properties/Resources.resx | 1 + Core/Repositories/RepositoryData.cs | 2 +- Core/Repositories/RepositoryDataManager.cs | 28 ++++++++++++------- Core/Types/Kraken.cs | 8 ++++++ GUI/Dialogs/DownloadsFailedDialog.Designer.cs | 1 + 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/Core/Net/Net.cs b/Core/Net/Net.cs index 88f6698efa..8d57d2ea97 100644 --- a/Core/Net/Net.cs +++ b/Core/Net/Net.cs @@ -51,10 +51,19 @@ public static string CurrentETag(Uri url) WebRequest req = WebRequest.Create(url); #pragma warning restore SYSLIB0014 req.Method = "HEAD"; - HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); - string val = resp.Headers["ETag"]?.Replace("\"", ""); - resp.Close(); - return val; + try + { + HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); + string val = resp.Headers["ETag"]?.Replace("\"", ""); + resp.Close(); + return val; + } + catch (WebException exc) + { + // Let the calling code keep going to get the actual problem + log.Debug($"Failed to get ETag from {url}", exc); + return null; + } } /// diff --git a/Core/Properties/Resources.resx b/Core/Properties/Resources.resx index 1b67fd5958..846a619157 100644 --- a/Core/Properties/Resources.resx +++ b/Core/Properties/Resources.resx @@ -151,6 +151,7 @@ Install the `mono-complete` package or equivalent for your operating system.The following inconsistencies were found: Loading modules from downloaded {0} repository...Should contain UserProgressDownloadSubstring from CmdLine Loaded download counts from {0} repository + Not a .tar.gz or .zip, cannot process: {0} `any_of` should not be combined with `{0}` {0} wishes to install {1}, but this file is registered to {2} Error unregistering {1}, file not removed: {0} diff --git a/Core/Repositories/RepositoryData.cs b/Core/Repositories/RepositoryData.cs index 65f493a679..54e7f718d1 100644 --- a/Core/Repositories/RepositoryData.cs +++ b/Core/Repositories/RepositoryData.cs @@ -187,7 +187,7 @@ public static RepositoryData FromDownload(string path, IGame game, IProgress(p => user.RaiseProgress(msg, p)), targets.Select(t => new FileInfo(t.filename).Length)); - foreach ((Repository repo, NetAsyncDownloader.DownloadTarget target) in toUpdate.Zip(targets)) + foreach ((var repo, var target) in toUpdate.Zip(targets)) { var file = target.filename; msg = string.Format(Properties.Resources.NetRepoLoadingModulesFromRepo, repo.name); - // Load the file, save to in memory cache log.InfoFormat("Loading {0}...", file); - var repoData = repositoriesData[repo] = - RepositoryData.FromDownload(file, game, progress); - // Save parsed data to disk - log.DebugFormat("Saving data for {0} repo...", repo.name); - repoData.SaveTo(GetRepoDataPath(repo)); - // Delete downloaded archive - log.DebugFormat("Deleting {0}...", file); - File.Delete(file); + try + { + // Load the file, save to in memory cache + var repoData = repositoriesData[repo] = + RepositoryData.FromDownload(file, game, progress); + // Save parsed data to disk + log.DebugFormat("Saving data for {0} repo...", repo.name); + repoData.SaveTo(GetRepoDataPath(repo)); + // Delete downloaded archive + log.DebugFormat("Deleting {0}...", file); + File.Delete(file); + } + catch (UnsupportedKraken kraken) + { + // Show parsing errors in the Downloads Failed popup + throw new DownloadErrorsKraken(Array.IndexOf(toUpdate, repo), kraken); + } progress.NextFile(); } // Commit these etags to disk diff --git a/Core/Types/Kraken.cs b/Core/Types/Kraken.cs index 3b9cc4479e..11930317fd 100644 --- a/Core/Types/Kraken.cs +++ b/Core/Types/Kraken.cs @@ -303,6 +303,14 @@ public DownloadErrorsKraken(List> errors) { Exceptions = new List>(errors); } + + public DownloadErrorsKraken(int index, Exception exc) + { + Exceptions = new List> + { + new KeyValuePair(index, exc), + }; + } } /// diff --git a/GUI/Dialogs/DownloadsFailedDialog.Designer.cs b/GUI/Dialogs/DownloadsFailedDialog.Designer.cs index dd180e2198..551549d76a 100644 --- a/GUI/Dialogs/DownloadsFailedDialog.Designer.cs +++ b/GUI/Dialogs/DownloadsFailedDialog.Designer.cs @@ -168,6 +168,7 @@ private void InitializeComponent() this.Icon = EmbeddedImages.AppIcon; this.MaximizeBox = false; this.MinimizeBox = false; + this.Padding = new System.Windows.Forms.Padding(8, 8, 8, 0); this.HelpButton = true; this.Name = "DownloadsFailedDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;