[pve-devel] [PATCH qemu-server v2 8/8] return error from guest-agent

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Feb 20 09:34:48 CET 2018


On 2/15/18 2:04 PM, Dominik Csapak wrote:
> in case of e.g. a non-existant guest-agent command, it would return
> { error: {someerrorobject} }
> but we did only include the 'return' property
> 
> in case we do not get any and the error property is set,
> return that
> 
> i looked at all the paths were we use the QMPClient, and either
> we have our own callback for the result,
> or we do not rely on the result being empty upon an error, so this
> should not break anything
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> new in v2
>  PVE/QMPClient.pm | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/PVE/QMPClient.pm b/PVE/QMPClient.pm
> index 9e32533..e08909b 100755
> --- a/PVE/QMPClient.pm
> +++ b/PVE/QMPClient.pm
> @@ -92,6 +92,8 @@ sub cmd {
>      my $callback = sub {
>  	my ($vmid, $resp) = @_;
>  	$result = $resp->{'return'};
> +	# return error message if we have one and no result

This comment just states what is readable from the code below,
so maybe it's not needed (''what' vs. 'why' comment)

> +	$result = { error => $resp->{'error'} } if !$result && $resp->{'error'};

Needs a defined check for $result, else an empty response gets overwritten.
Also, error is always true with this check - its a hash ref, which is also
true if empty.

So maybe just use:
    $result = { error => $resp->{error} } if !defined($result);

or 

$result = $resp->{result} // { error => $resp->{error} };

just as an idea...

>      };
>  
>      die "no command specified" if !($cmd && $cmd->{execute});
> 





More information about the pve-devel mailing list