Skip to content

Commit

Permalink
(WIP) Add check to prevent future dependency resolution failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed Jul 18, 2024
1 parent b5d47f5 commit 5b2cb7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/StringResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static class ErrorMessages
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
internal const string UnableToDowngrade = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to install older versions.";
internal const string DependencyFailedToInstall = "Failed to install {0} because a previous dependency failed.";
}
}
}
20 changes: 20 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,16 @@ Version was specified as '{0}'. It is possible that version

foreach (SourcePackageDependencyInfo packageDependencyInfo in resolvedPackages)
{
if (packageResultsToReturn.Any(r => r.Value.Success != true && packageDependencyInfo.Dependencies.Any(d => d.Id == r.Value.Identity.Id)))
{
var logMessage = StringResources.ErrorMessages.DependencyFailedToInstall.FormatWith(packageDependencyInfo.Id);
var x = new PackageResult(packageDependencyInfo.Id, packageDependencyInfo.Version.ToStringSafe(), string.Empty);
var nullResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id, x);
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
continue;
}

var packageRemoteMetadata = packagesToInstall.FirstOrDefault(p => p.Identity.Equals(packageDependencyInfo));

if (packageRemoteMetadata is null)
Expand Down Expand Up @@ -1569,6 +1579,16 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon
break;
}

if (packageResultsToReturn.Any(r => r.Value.Success != true && packageDependencyInfo.Dependencies.Any(d => d.Id == r.Value.Identity.Id)))
{
var logMessage = StringResources.ErrorMessages.DependencyFailedToInstall.FormatWith(packageDependencyInfo.Id, packageDependencyInfo.Version);
var x = new PackageResult(packageDependencyInfo.Id, packageDependencyInfo.Version.ToStringSafe(), string.Empty);
var nullResult = packageResultsToReturn.GetOrAdd(packageDependencyInfo.Id, x);
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
continue;
}

var packageRemoteMetadata = packagesToInstall.FirstOrDefault(p => p.Identity.Equals(packageDependencyInfo));

if (packageRemoteMetadata is null)
Expand Down

0 comments on commit 5b2cb7c

Please sign in to comment.