From: Peter Krempa <pkre...@redhat.com>

An error from virsh spews also backtrace:

  $ ./scripts/render_block_graph.py --vm doesnotexist
  error: failed to get domain 'doesnotexist'
  Traceback (most recent call last):
    File "/home/pipo/git/qemu.git/./scripts/render_block_graph.py", line 152, 
in <module>
      render_block_graph(qmp, out)
      ~~~~~~~~~~~~~~~~~~^^^^^^^^^^
    File "/home/pipo/git/qemu.git/./scripts/render_block_graph.py", line 47, in 
render_block_graph

 [snipped]

instead of just the important bits:

  $ ./scripts/render_block_graph.py --vm doesnotexist
  error: failed to get domain 'doesnotexist'

Catch the exception and exit. 'virsh' already printed the error.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 scripts/render_block_graph.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py
index 6f668dec51..3bfc751caa 100755
--- a/scripts/render_block_graph.py
+++ b/scripts/render_block_graph.py
@@ -106,7 +106,10 @@ def cmd(self, cmd):

         ar += ['qemu-monitor-command', self.name, json.dumps(m)]

-        reply = json.loads(subprocess.check_output(ar))
+        try:
+            reply = json.loads(subprocess.check_output(ar))
+        except subprocess.CalledProcessError:
+            sys.exit(1)

         if 'error' in reply:
             raise QMPError(reply)
-- 
2.48.1


Reply via email to