]> git.proxmox.com Git - pve-storage.git/commitdiff
api: FileRestore: decode and return proper error of file-restore listing
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 10 Nov 2022 10:36:32 +0000 (11:36 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 15 Nov 2022 10:03:08 +0000 (11:03 +0100)
since commit
ba690c40 ("file-restore: remove 'json-error' parameter from list_files")

in proxmox-backup, the file-restore binary will return the error as json
when called with '--output-format json' (which we do in PVE::PBSClient)

here, we assume that 'file-restore' will fail in that case, and we try
to use the return value as an array ref which fails, and the user never
sees the real error message.

To fix that, check the ref type of the return value and act accordingly

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Storage/FileRestore.pm

index ccc56e53035cfc69cf8185c68b8803b2a2a7c262..4033136bad333eac7a9bc46520772334a6e0e23d 100644 (file)
@@ -121,13 +121,24 @@ __PACKAGE__->register_method ({
        my $client = PVE::PBSClient->new($scfg, $storeid);
        my $ret = $client->file_restore_list($snap, $path, $base64);
 
-       # 'leaf' is a proper JSON boolean, map to perl-y bool
-       # TODO: make PBSClient decode all bools always as 1/0?
-       foreach my $item (@$ret) {
-           $item->{leaf} = $item->{leaf} ? 1 : 0;
+       if (ref($ret) eq "HASH") {
+           my $msg = $ret->{message};
+           if (my $code = $ret->{code}) {
+               die PVE::Exception->new("$msg\n", code => $code);
+           } else {
+               die "$msg\n";
+           }
+       } elsif (ref($ret) eq "ARRAY") {
+           # 'leaf' is a proper JSON boolean, map to perl-y bool
+           # TODO: make PBSClient decode all bools always as 1/0?
+           foreach my $item (@$ret) {
+               $item->{leaf} = $item->{leaf} ? 1 : 0;
+           }
+
+           return $ret;
        }
 
-       return $ret;
+       die "invalid proxmox-file-restore output";
     }});
 
 __PACKAGE__->register_method ({