Skip to content

Commit

Permalink
(GH-455) Summary - log reason for warnings/errors
Browse files Browse the repository at this point in the history
When providing the summary of an install/upgrade/uninstall, there is a
list of packages that had warnings and errors. If there is a warning or
error message to go along with that, provide that as part of the
summary.
  • Loading branch information
ferventcoder committed May 30, 2016
1 parent 72f510d commit 5ff630e
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
this.Log().Warn(ChocolateyLoggers.Important, "Warnings:");
foreach (var warning in packageInstalls.Where(p => p.Value.Warning).or_empty_list_if_null())
{
this.Log().Warn(ChocolateyLoggers.Important, " - {0}{1}".format_with(warning.Value.Name, warning.Value.ExitCode != 0 ? " (exit code {0})".format_with(warning.Value.ExitCode) : string.Empty));
var warningMessage = warning.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Warn);
this.Log().Warn(ChocolateyLoggers.Important, " - {0}{1}".format_with(warning.Value.Name, warningMessage != null ? " - {0}".format_with(warningMessage.Message) : string.Empty));
}
}

Expand All @@ -453,7 +454,11 @@ Please reboot at your earliest convenience.
this.Log().Error("Failures:");
foreach (var failure in packageInstalls.Where(p => !p.Value.Success).or_empty_list_if_null())
{
this.Log().Error(" - {0}{1}".format_with(failure.Value.Name, failure.Value.ExitCode != 0 ? " (exit code {0})".format_with(failure.Value.ExitCode) : string.Empty));
var errorMessage = failure.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Error);
this.Log().Error(" - {0}{1}{2}".format_with(failure.Value.Name,
failure.Value.ExitCode != 0 ? " (exited {0})".format_with(failure.Value.ExitCode) : string.Empty,
errorMessage != null ? " - {0}".format_with(errorMessage.Message) : string.Empty
));
}
}

Expand Down Expand Up @@ -653,7 +658,8 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
this.Log().Warn(ChocolateyLoggers.Important, "Warnings:");
foreach (var warning in packageUpgrades.Where(p => p.Value.Warning).or_empty_list_if_null())
{
this.Log().Warn(ChocolateyLoggers.Important, " - {0}{1}".format_with(warning.Value.Name, warning.Value.ExitCode != 0 ? " (exit code {0})".format_with(warning.Value.ExitCode) : string.Empty));
var warningMessage = warning.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Warn);
this.Log().Warn(ChocolateyLoggers.Important, " - {0}{1}".format_with(warning.Value.Name, warningMessage != null ? " - {0}".format_with(warningMessage.Message) : string.Empty));
}
}

Expand All @@ -675,7 +681,11 @@ Please reboot at your earliest convenience.
this.Log().Error("Failures:");
foreach (var failure in packageUpgrades.Where(p => !p.Value.Success).or_empty_list_if_null())
{
this.Log().Error(" - {0}{1}".format_with(failure.Value.Name, failure.Value.ExitCode != 0 ? " (exit code {0})".format_with(failure.Value.ExitCode) : string.Empty));
var errorMessage = failure.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Error);
this.Log().Error(" - {0}{1}{2}".format_with(failure.Value.Name,
failure.Value.ExitCode != 0 ? " (exited {0})".format_with(failure.Value.ExitCode) : string.Empty,
errorMessage != null ? " - {0}".format_with(errorMessage.Message) : string.Empty
));
}
}

Expand Down Expand Up @@ -734,6 +744,7 @@ public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfi
get_environment_after(config, environmentBefore, out environmentChanges, out environmentRemovals);

var uninstallFailures = packageUninstalls.Count(p => !p.Value.Success);
var uninstallWarnings = packageUninstalls.Count(p => p.Value.Warning);
var rebootPackages = packageUninstalls.Count(p => new[] { 1641, 3010 }.Contains(p.Value.ExitCode));
this.Log().Warn(() => @"{0}{1} uninstalled {2}/{3} packages. {4} packages failed.{0} See the log for details ({5}).".format_with(
Environment.NewLine,
Expand All @@ -744,6 +755,16 @@ public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfi
_fileSystem.combine_paths(ApplicationParameters.LoggingLocation, ApplicationParameters.LoggingFile)
));

if (uninstallWarnings != 0)
{
this.Log().Warn(ChocolateyLoggers.Important, "Warnings:");
foreach (var warning in packageUninstalls.Where(p => p.Value.Warning).or_empty_list_if_null())
{
var warningMessage = warning.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Warn);
this.Log().Warn(ChocolateyLoggers.Important, " - {0}{1}".format_with(warning.Value.Name, warningMessage != null ? " - {0}".format_with(warningMessage.Message) : string.Empty));
}
}

if (rebootPackages != 0)
{
this.Log().Warn(ChocolateyLoggers.Important, "Packages needing reboot:");
Expand All @@ -762,7 +783,11 @@ Please reboot at your earliest convenience.
this.Log().Error("Failures");
foreach (var failure in packageUninstalls.Where(p => !p.Value.Success).or_empty_list_if_null())
{
this.Log().Error(" - {0}{1}".format_with(failure.Value.Name, failure.Value.ExitCode != 0 ? " (exit code {0})".format_with(failure.Value.ExitCode) : string.Empty));
var errorMessage = failure.Value.Messages.FirstOrDefault(m => m.MessageType == ResultType.Error);
this.Log().Error(" - {0}{1}{2}".format_with(failure.Value.Name,
failure.Value.ExitCode != 0 ? " (exited {0})".format_with(failure.Value.ExitCode) : string.Empty,
errorMessage != null ? " - {0}".format_with(errorMessage.Message) : string.Empty
));
}
}

Expand Down

0 comments on commit 5ff630e

Please sign in to comment.