From 3c30bfec0077e2f021745a7814449ae72c844ba4 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sun, 11 Dec 2022 01:31:44 +0100 Subject: [PATCH] Winget Error Handling --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 9 ++++++++- Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index cf79a12..116de25 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -84,7 +84,7 @@ if (Test-Network) { } else { Write-Log "List doesn't exist!" "Red" - Exit 0 + Exit 1 } } } @@ -125,6 +125,13 @@ if (Test-Network) { Write-Log "Checking application updates on Winget Repository..." "yellow" $outdated = Get-WingetOutdatedApps + #If something is wrong with the winget source, exit + if (($outdated -like "Problem:*")) { + Write-Log "An error occured, exiting..." "red" + Write-Log "$outdated" "red" + Exit 1 + } + #Log list of app to update foreach ($app in $outdated) { #List available updates diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 index 4634cd2..b32e45c 100644 --- a/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1 @@ -11,9 +11,9 @@ function Get-WingetOutdatedApps { #Get list of available upgrades on winget format $upgradeResult = & $Winget upgrade --source winget | Out-String - #Start Convertion of winget format to an array. Check if "-----" exists + #Start Convertion of winget format to an array. Check if "-----" exists (Winget Error Handling) if (!($upgradeResult -match "-----")) { - return + return "Problem:$upgradeResult" } #Split winget output to lines