From 487b322b91f9ee13eb9dc5bdc79084e58ed7b38f Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 1 Mar 2018 17:00:58 +0800 Subject: [PATCH] ceph.in: use a differnt variable for holding thrown exception otherwise, we will have $ bin/ceph osd Traceback (most recent call last): File "bin/ceph", line 1178, in retval = main() File "bin/ceph", line 1109, in main verbose) File "bin/ceph", line 535, in new_style_command valid_dict = validate_command(sigdict, cmdargs, verbose) File "/var/ceph/ceph/src/pybind/ceph_argparse.py", line 1083, in validate_command if found or e: UnboundLocalError: local variable 'e' referenced before assignment when using python3 Signed-off-by: Kefu Chai --- src/pybind/ceph_argparse.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index cbc2adad70e09..45049797d5922 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -1049,7 +1049,7 @@ def validate_command(sigdict, args, verbose=False): print("bestcmds_sorted: ", file=sys.stderr) pprint.PrettyPrinter(stream=sys.stderr).pprint(bestcmds_sorted) - e = None + ex = None # for everything in bestcmds, look for a true match for cmdsig in bestcmds_sorted: for cmd in cmdsig.values(): @@ -1063,6 +1063,7 @@ def validate_command(sigdict, args, verbose=False): # the right command yet pass except ArgumentMissing as e: + ex = e if len(bestcmds) == 1: found = cmd break @@ -1075,12 +1076,13 @@ def validate_command(sigdict, args, verbose=False): print('Not enough args supplied for ', concise_sig(sig), file=sys.stderr) except ArgumentError as e: + ex = e # Solid mismatch on an arg (type, range, etc.) # Stop now, because we have the right command but # some other input is invalid found = cmd break - if found or e: + if found or ex: break if found: -- 2.39.5