From: Tony Asleson Date: Thu, 26 Mar 2020 18:07:45 +0000 (-0500) Subject: nvmetcli: Improve IOError handling on restore X-Git-Tag: v0.8~13 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=48b8f318e0594d7adfec290ae47d9308eb0f65af;p=users%2Fhch%2Fnvmetcli.git nvmetcli: Improve IOError handling on restore Not all IOErrors are caused by specifying a missing configuration file. When the file is present, dump the error exception text too, so the user has a better idea what is wrong. Signed-off-by: Tony Asleson Signed-off-by: Christoph Hellwig --- diff --git a/nvmetcli b/nvmetcli index 3d8c16e..a646232 100755 --- a/nvmetcli +++ b/nvmetcli @@ -24,6 +24,7 @@ import os import sys import configshell_fb as configshell import nvmet as nvme +import errno from string import hexdigits import uuid @@ -674,16 +675,26 @@ def save(to_file): def restore(from_file): + errors = None + try: errors = nvme.Root().restore_from_file(from_file) - except IOError: - # Not an error if the restore file is not present - print("No saved config file at %s, ok, exiting" % from_file) - sys.exit(0) + except IOError as e: + if e.errno == errno.ENOENT: + # Not an error if the restore file is not present + print("No saved config file at %s, ok, exiting" % from_file) + sys.exit(0) + else: + print("Error processing config file at %s, error %s, exiting" % + (from_file, str(e))) + sys.exit(1) + # These errors are non-fatal for error in errors: print(error) + sys.exit(0) + def clear(unused): nvme.Root().clear_existing()