Skip to content

Commit 9d18a01

Browse files
committed
Merge branch 'adammodlin-master' into dev
2 parents bf0cf45 + 2dfed5c commit 9d18a01

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

src/NuGet.Server.Core/Infrastructure/ServerPackageRepository.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,21 @@ private HashSet<ServerPackage> ReadPackagesFromDisk()
457457

458458
Parallel.ForEach(packages, package =>
459459
{
460-
// Create server package
461-
var serverPackage = CreateServerPackage(package, enableDelisting);
460+
ServerPackage serverPackage;
462461

463-
// Add the package to the cache, it should not exist already
464-
if (cachedPackages.Contains(serverPackage))
462+
//Try to create the server package and ignore a bad package if it fails
463+
var couldCreateServerPackage = TryCreateServerPackage(package, enableDelisting, out serverPackage);
464+
if (couldCreateServerPackage)
465465
{
466-
_logger.Log(LogLevel.Warning, "Duplicate package found - {0} {1}", package.Id, package.Version);
467-
}
468-
else
469-
{
470-
cachedPackages.Add(serverPackage);
466+
// Add the package to the cache, it should not exist already
467+
if (cachedPackages.Contains(serverPackage))
468+
{
469+
_logger.Log(LogLevel.Warning, "Duplicate package found - {0} {1}", package.Id, package.Version);
470+
}
471+
else
472+
{
473+
cachedPackages.Add(serverPackage);
474+
}
471475
}
472476
});
473477

@@ -543,6 +547,21 @@ private ServerPackage CreateServerPackage(IPackage package, bool enableDelisting
543547
return serverPackage;
544548
}
545549

550+
private bool TryCreateServerPackage(IPackage package, bool enableDelisting, out ServerPackage serverPackage)
551+
{
552+
try
553+
{
554+
serverPackage = CreateServerPackage(package, enableDelisting);
555+
return true;
556+
}
557+
catch(Exception e)
558+
{
559+
serverPackage = null;
560+
_logger.Log(LogLevel.Warning, "Unable to create server package - {0} {1}: {2}", package.Id, package.Version, e.Message);
561+
return false;
562+
}
563+
}
564+
546565
/// <summary>
547566
/// Sets the current cache to null so it will be regenerated next time.
548567
/// </summary>

0 commit comments

Comments
 (0)