Skip to content

Commit a8ba801

Browse files
authored
Merge pull request #36 from EncoreTechnologies/hotfix/size-checks
Fix bug where .size was on a potentially undef value in patching::update_history
2 parents 9c8ad93 + 94307a4 commit a8ba801

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file.
88

99
Contributed by Vadym Chepkov (@vchepkov)
1010

11+
* Fixed a bug where if `patching::update_history` task was called and no results were returned
12+
the `patching::update_history` plan would fail. Now, we default to an empty array so a 0
13+
is displayed.
14+
15+
Contributed by Nick Maludy (@nmaludy)
16+
1117
## Release 1.0.0 (2020-02-28)
1218

1319
* **BREAKING CHANGE**

plans/update_history.pp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@
5454
$header = sprintf($row_format, 'host', 'upgraded', 'installed')
5555
$divider = '-----------------------------------------------------'
5656
$output = $_history.map|$hist| {
57-
$num_upgraded = $hist['upgraded'].size
58-
$num_installed = $hist['installed'].size
57+
# in case history doesn't contain any updates
58+
$upgraded = pick($hist['upgraded'], [])
59+
$installed = pick($hist['installed'], [])
60+
$num_upgraded = $upgraded.size
61+
$num_installed = $installed.size
5962
$row_format = '%-30s | %-8s | %-8s'
6063
$message = sprintf($row_format, $hist.target.name, $num_upgraded, $num_installed)
6164
$message
@@ -68,8 +71,10 @@
6871
$csv_header = "host,action,name,version,kb (windows only)\n"
6972
$report = $_history.reduce($csv_header) |$res_memo, $res| {
7073
$hostname = $res.target.name
71-
$num_updates = $res['upgraded'].length
72-
$host_updates = $res['upgraded'].reduce('') |$up_memo, $up| {
74+
# in case history doesn't contain any updates
75+
$upgraded = pick($res['upgraded'], [])
76+
$num_updates = $upgraded.length
77+
$host_updates = $upgraded.reduce('') |$up_memo, $up| {
7378
$name = $up['name']
7479
$version = ('version' in $up) ? {
7580
true => $up['version'],

0 commit comments

Comments
 (0)