Skip to content

Commit 17dd179

Browse files
authored
Merge pull request #61 from EncoreTechnologies/hotfix/chocolatey-available-updates
Fix parsing bug in available_update_windows task
2 parents 3a4bcc4 + e02a016 commit 17dd179

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ All notable changes to this project will be documented in this file.
1616
* `patching_update_provider`: Parameter sets the provider in the update tasks.
1717

1818
Contributed by Bill Sirinek (@sirinek)
19+
20+
* Fixed bug in `patching::available_updates_windows` where if `choco outdated` printed an
21+
error, but returned a `0` exit status our output parsing code was throwing an exception
22+
causing a unhelpful error to be printed. Now, we check for this condition and if we
23+
can't successfully parse the output of `choco outdated` we explicitly fail the task
24+
and return the raw output from the command.
25+
26+
Contributed by Nick Maludy (@nmaludy)
1927

2028
## Release 1.1.0 (2020-04-15)
2129

tasks/available_updates_windows.ps1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ function AvailableUpdates-Chocolatey([bool]$choco_required) {
7373
# output is in the format:
7474
# package name|current version|available version|pinned?
7575
foreach ($line in $output) {
76-
$parts = $line.split('|')
76+
$parts = @($line.split('|'))
77+
if ($parts.Length -lt 4) {
78+
return @{
79+
'result' = $output;
80+
'exit_code' = 102;
81+
'error' = '"choco outdated" command returned data in an unknown format (couldnt find at least 4x "|" characters). Check the "result" parameter for the raw output from the command. Guessing there was some unexpected error and "choco outdated" still returned an exit code of 0.';
82+
}
83+
}
7784
$updateList += @{
7885
'name' = $parts[0];
7986
'version_old' = $parts[1];
@@ -101,13 +108,22 @@ if ($provider -eq '') {
101108
$exit_code = 0
102109
if ($provider -eq 'windows') {
103110
$data_windows = AvailableUpdates-Windows
104-
$result = @{"updates" = @($data_windows['result'])}
105111
$exit_code = $data_windows['exit_code']
112+
if ($exit_code -eq 0) {
113+
$result = @{"updates" = @($data_windows['result'])}
114+
}
115+
else {
116+
$result = @{'error_windows' = $data_windows}
117+
}
106118
} elseif ($provider -eq 'chocolatey') {
107119
$data_chocolatey = AvailableUpdates-Chocolatey($True)
108-
Write-Output $data_chocolatey
109-
$result = @{"updates" = @($data_chocolatey['result'])}
110120
$exit_code = $data_chocolatey['exit_code']
121+
if ($exit_code -eq 0) {
122+
$result = @{"updates" = @($data_chocolatey['result'])}
123+
}
124+
else {
125+
$result = @{'error_chocolatey' = $data_chocolatey}
126+
}
111127
} elseif ($provider -eq 'all') {
112128
$result = @{"updates" = @()}
113129
$exit_code = 0

0 commit comments

Comments
 (0)