Skip to content

Commit

Permalink
Fix error handling in run_from_cli for maid.
Browse files Browse the repository at this point in the history
  • Loading branch information
ast0815 committed May 28, 2019
1 parent 40597dd commit 103468e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion t2kdm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Helpful tools to manage the T2K data on the grid.
"""

__version__ = '1.7.1-dev'
__version__ = '1.7.1'

import configuration
from configuration import _branding
Expand Down
12 changes: 6 additions & 6 deletions t2kdm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ def run_from_cli(self, argstring, _return=False, **kwargs):
Then it returns the actual return value.
"""

ret = 1 # Arbitrary error code

try:
args = shlex.split(argstring)
except ValueError as e: # Catch errors from bad bash syntax
print_(e)
return False
if _return:
return ret
else:
return False

ret = False
try: # We do *not* want to exit after printing a help message or erroring, so we have to catch that.
ret = self.run_from_arglist(args, **kwargs)
except dm.backends.BackendException as e:
print_(e)
except interactive.InteractiveException as e:
print_(e)
except Exception as e:
print_(e)
except SystemExit:
Expand Down
1 change: 1 addition & 0 deletions t2kdm/maid.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def __init__(self, **kwargs):
super(CommandTask, self).__init__(**kwargs)

def _do(self):
# Check interactive command for success return code
return self.command.run_from_cli(self.argstr, _return=True) == 0

def __str__(self):
Expand Down
6 changes: 3 additions & 3 deletions t2kdm/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ def run_read_only_tests():
print_("Testing Commands...")
with no_output(True):
assert(cmd.ls.run_from_cli('-l /') == False)
assert(cmd.ls.run_from_cli('.') == False)
assert(cmd.ls.run_from_cli('/', _return=True) == 0)

cmd.ls.run_from_cli('abc') # This should not work, but not throw exception
cmd.ls.run_from_cli('"abc') # This should not work, but not throw exception
assert(cmd.ls.run_from_cli('abc') == False) # This should not work, but not throw exception
assert(cmd.ls.run_from_cli('"abc', _return=True) != 0) # This should not work, but not throw exception
with fake_argv(['%s-ls'%(dm._branding,), '/']):
assert(cmd.ls.run_from_console() == 0) # This should work
with fake_argv(['%s-cli'%(dm._branding), '/']):
Expand Down

0 comments on commit 103468e

Please sign in to comment.