From b3d7568fb67535a66a9ba38f39ea3adde717e07a Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 16 Mar 2023 16:18:48 +0100 Subject: [PATCH] cli formatter: check data ref when printing array Signed-off-by: Thomas Lamprecht --- src/PVE/CLIFormatter.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm index a267dcf..199bee7 100644 --- a/src/PVE/CLIFormatter.pm +++ b/src/PVE/CLIFormatter.pm @@ -399,7 +399,12 @@ sub print_api_result { my $schema = { type => 'array', items => { type => 'object' }}; print_api_list($kvstore, $schema, ['key', 'value'], $options, $terminal_opts); } elsif ($type eq 'array') { - return if !scalar(@$data); + if (ref($data) eq 'ARRAY') { + return if !scalar(@$data); + } elsif (ref($data) eq 'HASH') { + return if !scalar($data->%*); + die "got hash object, but result schema specified array!\n" + } my $item_type = $result_schema->{items}->{type}; if ($item_type eq 'object') { print_api_list($data, $result_schema, $props_to_print, $options, $terminal_opts); -- 2.39.2