From 14f99a16145b73f1490e2c05fe2d12c05e05e3a2 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 10 Nov 2022 11:36:32 +0100 Subject: [PATCH] api: FileRestore: decode and return proper error of file-restore listing 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 --- PVE/API2/Storage/FileRestore.pm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/PVE/API2/Storage/FileRestore.pm b/PVE/API2/Storage/FileRestore.pm index ccc56e5..4033136 100644 --- a/PVE/API2/Storage/FileRestore.pm +++ b/PVE/API2/Storage/FileRestore.pm @@ -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 ({