]> git.proxmox.com Git - pve-common.git/commitdiff
cli formatter: check data ref when printing array
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 16 Mar 2023 15:18:48 +0000 (16:18 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 16 Mar 2023 15:18:48 +0000 (16:18 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/CLIFormatter.pm

index a267dcfc9e0bd2e1a692b462c772ef6957899fdb..199bee764f352836a37e9374ba847ceefb64590b 100644 (file)
@@ -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);