]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Improve "ceph_argparse.py: add stderr note if nonrequired param is invalid"
authorDavid Zafman <dzafman@redhat.com>
Tue, 17 Mar 2015 03:34:10 +0000 (20:34 -0700)
committerDavid Zafman <dzafman@redhat.com>
Tue, 17 Mar 2015 15:19:44 +0000 (08:19 -0700)
When processing arguments stash an exception which is seen when looking
for another argument type.  If we have extra args at the end, output
information about the exception which probably caused the problem.

Fixes: #11093
Original fix: 71ff794eca7dd57a0b0473530f685069ac9987f0

Signed-off-by: David Zafman <dzafman@redhat.com>
src/pybind/ceph_argparse.py

index 3d202da5bcdefe9fc867b5f870905a7636a6f03a..12f0b708a110298d0a2871e2995355f5f9f0d168 100644 (file)
@@ -868,7 +868,7 @@ def validate(args, signature, partial=False):
                 if not desc.req:
                     # if not required, just push back; it might match
                     # the next arg
-                    print >> sys.stderr, myarg, 'not valid: ', str(e)
+                    save_exception = [ myarg, e ]
                     myargs.insert(0, myarg)
                     break
                 else:
@@ -880,12 +880,16 @@ def validate(args, signature, partial=False):
             # Whew, valid arg acquired.  Store in dict
             matchcnt += 1
             store_arg(desc, d)
+            # Clear prior exception
+            save_exception = None
 
     # Done with entire list of argdescs
     if matchcnt < reqsiglen:
         raise ArgumentTooFew("not enough arguments given")
 
     if myargs and not partial:
+        if save_exception:
+            print >> sys.stderr, save_exception[0], 'not valid: ', str(save_exception[1])
         raise ArgumentError("unused arguments: " + str(myargs))
 
     # Finally, success