diff mbox series

[3/3] scripts: render_block_graph: Avoid backtrace on error from virsh

Message ID 8926805f0283b8aca7d709ae06b1103db857cbde.1742315602.git.pkrempa@redhat.com (mailing list archive)
State New
Headers show
Series scripts: render_block_graph: Fix with new python and improve argument parsing | expand

Commit Message

Peter Krempa March 18, 2025, 4:36 p.m. UTC
From: Peter Krempa <pkrempa@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 <pkrempa@redhat.com>
---
 scripts/render_block_graph.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py
index 7a6738410c..e2bb83b60e 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)