From 27591290c718e768c523b3698429ce34e4686ba7 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 4 Apr 2024 12:55:40 +0200 Subject: [PATCH] use stderr from qemu-img invocation as error Instead of just using it as a warning and then trying to parse an empty string as json. For example, trying to parse unsupported vmdks, previously we'd see something like this: qemu-img: Could not open '/run/pve/import/esxi/foo/mnt/ha-datacenter/vsanDatastore/asdf/asdf-000001.vmdk': Unsupported image type 'vsanSparse' could not parse qemu-img info command output for '/run/pve/import/esxi/foo/mnt/ha-datacenter/vsanDatastore/asdf/asdf-000001.vmdk' - malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at src/PVE/Storage/Plugin.pm line 962, line 960. Now it simply shows: qemu-img: Could not open '/run/pve/import/esxi/foo/mnt/ha-datacenter/vsanDatastore/asdf/asdf-000001.vmdk': Unsupported image type 'vsanSparse' Signed-off-by: Wolfgang Bumiller --- src/PVE/Storage/Plugin.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 7456c8e..22a9729 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -950,14 +950,21 @@ sub file_size_info { } my $json = ''; + my $err_output = ''; eval { run_command(['/usr/bin/qemu-img', 'info', '--output=json', $filename], timeout => $timeout, outfunc => sub { $json .= shift }, - errfunc => sub { warn "$_[0]\n" } + errfunc => sub { $err_output .= shift . "\n"}, ); }; warn $@ if $@; + if ($err_output) { + # if qemu did not output anything to stdout we die with stderr as an error + die $err_output if !$json; + # otherwise we warn about it and try to parse the json + warn $err_output; + } my $info = eval { decode_json($json) }; if (my $err = $@) {