On 2/10/20 9:16 AM, Alexandre Derumier wrote:
> When a remote node not return a json, we got and error.
> 
> This is fixing this:
> 
> pvesh set /nodes/localname/network
> UPID:kvmformation2:0034937B:09352894:5E41106C:srvreload:networking:root@pam:
> 
> pvesh set /nodes/remotenode/network
> JSON text must be an object or array (but found number, string, true, false 
> or null, use allow_nonref to allow this) at /usr/share/perl5/PVE/CLI/pvesh.pm 
> line 125.
> 
> This patch simply return raw result if it's not a json
> 
> Signed-off-by: Alexandre Derumier <aderum...@odiso.com>
> ---
>  PVE/CLI/pvesh.pm | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/CLI/pvesh.pm b/PVE/CLI/pvesh.pm
> index 9b8e3245..56d32c3f 100755
> --- a/PVE/CLI/pvesh.pm
> +++ b/PVE/CLI/pvesh.pm
> @@ -122,7 +122,14 @@ sub proxy_handler {
>      PVE::Tools::run_command($remcmd, errmsg => "proxy handler failed",
>                           outfunc => sub { $json .= shift });
>  
> -    return decode_json($json);
> +    my $decoded_json = undef;
> +    eval {
> +     $decoded_json = decode_json($json);
> +    };
> +    if ($@) {
> +     return $json;
> +    }
> +    return $decoded_json;
>  }
>  
>  sub extract_children {
> 

applied, with a followup. $json as name for the possible not-JSON data was a bit
confusing IMO. Also, one can use the fact that the last statement in an eval 
get's
returned from it and thus write:

my $decoded_json = eval { decode_json($json) };

it's slightly cleaner and shorter to read, but just a nit-pick :-) Thanks!

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to