Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show repo ETag and parsing errors in Failed Downloads #4030

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Core/Net/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Install the `mono-complete` package or equivalent for your operating system.</va
<data name="NetRepoInconsistenciesHeader" xml:space="preserve"><value>The following inconsistencies were found:</value></data>
<data name="NetRepoLoadingModulesFromRepo" xml:space="preserve"><value>Loading modules from downloaded {0} repository...</value><comment>Should contain UserProgressDownloadSubstring from CmdLine</comment></data>
<data name="NetRepoLoadedDownloadCounts" xml:space="preserve"><value>Loaded download counts from {0} repository</value></data>
<data name="NetRepoNotATarGz" xml:space="preserve"><value>Not a .tar.gz or .zip, cannot process: {0}</value></data>
<data name="JsonRelationshipConverterAnyOfCombined" xml:space="preserve"><value>`any_of` should not be combined with `{0}`</value></data>
<data name="RegistryFileConflict" xml:space="preserve"><value>{0} wishes to install {1}, but this file is registered to {2}</value></data>
<data name="RegistryFileNotRemoved" xml:space="preserve"><value>Error unregistering {1}, file not removed: {0}</value></data>
Expand Down
2 changes: 1 addition & 1 deletion Core/Repositories/RepositoryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static RepositoryData FromDownload(string path, IGame game, IProgress<lon
{
case FileType.TarGz: return FromTarGz(path, game, progress);
case FileType.Zip: return FromZip(path, game, progress);
default: throw new UnsupportedKraken($"Not a .tar.gz or .zip, cannot process: {path}");
default: throw new UnsupportedKraken(string.Format(Properties.Resources.NetRepoNotATarGz, path));
}
}

Expand Down
28 changes: 18 additions & 10 deletions Core/Repositories/RepositoryDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,29 @@ public UpdateResult Update(Repository[] repos,
var progress = new ProgressFilesOffsetsToPercent(
new Progress<int>(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
Expand Down
8 changes: 8 additions & 0 deletions Core/Types/Kraken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ public DownloadErrorsKraken(List<KeyValuePair<int, Exception>> errors)
{
Exceptions = new List<KeyValuePair<int, Exception>>(errors);
}

public DownloadErrorsKraken(int index, Exception exc)
{
Exceptions = new List<KeyValuePair<int, Exception>>
{
new KeyValuePair<int, Exception>(index, exc),
};
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions GUI/Dialogs/DownloadsFailedDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading