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

[nonGallery] Adjust try blocks in TFM backfill, repair empty TFM metadata case #8531

Merged
merged 1 commit into from
Apr 21, 2021
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
12 changes: 9 additions & 3 deletions src/GalleryTools/Commands/BackfillCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Xml;
using System.Xml.Linq;
using GalleryTools.Utils;
using Microsoft.IdentityModel.JsonWebTokens;
using NuGet.Services.Sql;

namespace GalleryTools.Commands
Expand Down Expand Up @@ -116,8 +117,7 @@ public async Task Collect(SqlConnection connection, Uri serviceDiscoveryUri, Dat

var repository = new EntityRepository<Package>(context);

var packages = repository.GetAll()
.Include(p => p.PackageRegistration);
var packages = repository.GetAll().Include(p => p.PackageRegistration);
if (QueryIncludes != null)
{
packages = packages.Include(QueryIncludes);
Expand Down Expand Up @@ -233,6 +233,10 @@ public async Task Update(SqlConnection connection, string fileName)
var repository = new EntityRepository<Package>(context);

var packages = repository.GetAll().Include(p => p.PackageRegistration);
if (QueryIncludes != null)
{
packages = packages.Include(QueryIncludes);
}

using (var csv = CreateCsvReader(fileName))
{
Expand Down Expand Up @@ -355,7 +359,9 @@ private CsvReader CreateCsvReader(string fileName)

var reader = new StreamReader(fileName);

return new CsvReader(reader, configuration);
var csvReader = new CsvReader(reader, configuration);
csvReader.Configuration.MissingFieldFound = null;
return csvReader;
}

private Configuration CreateCsvConfiguration()
Expand Down
56 changes: 28 additions & 28 deletions src/GalleryTools/Commands/BackfillTfmMetadataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,31 @@ protected override List<string> ReadMetadata(IList<string> files, NuspecReader n
try
{
supportedFrameworks = _packageService.GetSupportedFrameworks(nuspecReader, files);
}
catch (ArgumentException)
{
// do nothing--this is a known scenario and we'll skip this package quietly, which will give us a more useful error log file
}

foreach (var tfm in supportedFrameworks)
{
// We wrap this in a try-catch because some poorly-crafted portable TFMs will make it through GetSupportedFrameworks and fail here, e.g. for a
// non-existent profile name like "Profile1", which will cause GetShortFolderName to throw. We want to fail silently for these as this is a known
// scenario (more useful error log) and not failing will allow us to still capture all of the valid TFMs.
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs#L297
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs#L487 }
try
foreach (var tfm in supportedFrameworks)
{
var tfmToAdd = tfm.ToShortNameOrNull();
if (!string.IsNullOrEmpty(tfmToAdd))
// We wrap this in a try-catch because some poorly-crafted portable TFMs will make it through GetSupportedFrameworks and fail here, e.g. for a
// non-existent profile name like "Profile1", which will cause GetShortFolderName to throw. We want to fail silently for these as this is a known
// scenario (more useful error log) and not failing will allow us to still capture all of the valid TFMs.
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs#L297
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs#L487 }
try
{
supportedTFMs.Add(tfmToAdd);
var tfmToAdd = tfm.ToShortNameOrNull();
if (!string.IsNullOrEmpty(tfmToAdd))
{
supportedTFMs.Add(tfmToAdd);
}
}
catch
{
// skip this TFM and only collect well-formatted ones
}
}
catch
{
// skip this TFM and only collect well-formatted ones
}
}
catch (ArgumentException)
{
// do nothing--this is a known scenario and we'll skip this package quietly, which will give us a more useful error log file
}

return supportedTFMs;
}
Expand All @@ -79,17 +78,18 @@ protected override void UpdatePackage(Package package, List<string> metadata, En
{
// Note that extracting old TFMs may throw for formatting reasons. In this case we'll force a full replacement by leaving the collection empty.
var existingTFMs = Enumerable.Empty<string>();
if (package.SupportedFrameworks != null)
try
{
try
{
existingTFMs = package.SupportedFrameworks.Select(f => f.FrameworkName.GetShortFolderName()).OrderBy(f => f);
}
catch
if (package.SupportedFrameworks != null)
{
// do nothing and replace in full
// We'll force this enumerable to a list to force all potential throws
existingTFMs = package.SupportedFrameworks.Select(f => f.FrameworkName.GetShortFolderName()).OrderBy(f => f).ToList();
}
}
catch
{
// do nothing and replace in full
}

var newTFMs = metadata == null || metadata.Count == 0
? Enumerable.Empty<string>()
Expand Down