[pve-devel] [PATCH common] cli-formatter: avoid warning when trying to sort on undefined key

Christian Ebner c.ebner at proxmox.com
Thu Nov 21 15:21:10 CET 2019


Example:
    pvesh get /nodes/{node}/qemu/{vmid}/rrddata --timeframe day

If the sorting key is not defined in the dataset, e.g. when a VM was not running
for some time within the given timeframe, this resulted in several ugly warnings.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 src/PVE/CLIFormatter.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
index 0e9cbe6..65802f8 100644
--- a/src/PVE/CLIFormatter.pm
+++ b/src/PVE/CLIFormatter.pm
@@ -175,9 +175,9 @@ sub print_text_table {
     if (defined($sort_key) && $sort_key ne 0) {
 	my $type = $returnprops->{$sort_key}->{type} // 'string';
 	if ($type eq 'integer' || $type eq 'number') {
-	    @$data = sort { $a->{$sort_key} <=> $b->{$sort_key} } @$data;
+	    @$data = sort { defined $a->{$sort_key} <=> defined $b->{$sort_key} } @$data;
 	} else {
-	    @$data = sort { $a->{$sort_key} cmp $b->{$sort_key} } @$data;
+	    @$data = sort { defined $a->{$sort_key} cmp defined $b->{$sort_key} } @$data;
 	}
     }
 
-- 
2.20.1




More information about the pve-devel mailing list