From 92759efbf5e091207242644d233eddd18a9f91e8 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 10 Jan 2020 13:57:04 +0100 Subject: [PATCH] python: improve errors in inspect_vm example When validating user input, print an error message and exit, instead of either asserting or raising a non-existing exception. --- python/examples/inspect_vm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/examples/inspect_vm.py b/python/examples/inspect_vm.py index 22cd70f28..dcf3b538c 100644 --- a/python/examples/inspect_vm.py +++ b/python/examples/inspect_vm.py @@ -3,7 +3,9 @@ import sys import guestfs -assert(len(sys.argv) == 2) +if len(sys.argv) < 2: + print("inspect_vm: missing disk image to inspect", file=sys.stderr) + sys.exit(1) disk = sys.argv[1] # All new Python code should pass python_return_dict=True @@ -21,7 +23,8 @@ g.launch() # Ask libguestfs to inspect for operating systems. roots = g.inspect_os() if len(roots) == 0: - raise(Error("inspect_vm: no operating systems found")) + print("inspect_vm: no operating systems found", file=sys.stderr) + sys.exit(1) for root in roots: print("Root device: %s" % root)