Clean up & simplify error handling and reporting

This commit is contained in:
Jeffrey
2026-08-16 21:21:10 +02:00
parent 492a374f5c
commit dded2da3a7
3 changed files with 9 additions and 40 deletions
+3 -15
View File
@@ -114,13 +114,7 @@ function Show-ApplyModal {
try {
Invoke-AllChanges
$appRemovalFailureCount = [int]$script:AppRemovalFailures
$applyFailureCount = [int]$script:ApplyFeatureFailures
$undoFailureCount = [int]$script:UndoFeatureFailures
$featureFailureCount = $applyFailureCount + $undoFailureCount
$prerequisiteFailureCount = [int]$script:PrerequisiteFailures
# App removals are a subset of failed features, so adding both counters
# would report each affected feature twice.
$featureFailureCount = [int]$script:FeatureFailures
$failureCount = $featureFailureCount
$appRemovalVerificationUnavailable = [bool]$script:AppRemovalVerificationUnavailable
@@ -149,7 +143,7 @@ function Show-ApplyModal {
$script:ApplyCompletionIconEl.Foreground = [System.Windows.Media.SolidColorBrush]::new([System.Windows.Media.ColorConverter]::ConvertFromString("#e8912d"))
$script:ApplyCompletionTitleEl.Text = "Cancelled"
$script:ApplyCompletionMessageEl.Text = "Script execution was cancelled by the user."
} elseif ($failureCount -gt 0 -or $prerequisiteFailureCount -gt 0 -or $appRemovalVerificationUnavailable) {
} elseif ($failureCount -gt 0 -or $appRemovalVerificationUnavailable) {
if ($failureCount -gt 0) {
Write-Host "Script completed with $failureCount error(s)."
}
@@ -162,13 +156,7 @@ function Show-ApplyModal {
}
else {
$script:ApplyCompletionTitleEl.Text = "Changes Applied with Errors"
$failureMessages = @()
if ($appRemovalFailureCount -gt 0) { $failureMessages += "$appRemovalFailureCount app removal(s) failed" }
if ($applyFailureCount -gt 0) { $failureMessages += "$applyFailureCount feature change(s) failed to apply" }
if ($undoFailureCount -gt 0) { $failureMessages += "$undoFailureCount feature change(s) failed to undo" }
if ($prerequisiteFailureCount -gt 0) { $failureMessages += "$prerequisiteFailureCount requested prerequisite(s) could not be completed" }
if ($appRemovalVerificationUnavailable) { $failureMessages += "Unable to verify if all apps were uninstalled successfully" }
$script:ApplyCompletionMessageEl.Text = "$($failureMessages -join '; '). See console for details."
$script:ApplyCompletionMessageEl.Text = "$featureFailureCount change(s) failed. See console for details."
}
} else {
Write-Host "All changes have been applied successfully!"