-
Notifications
You must be signed in to change notification settings - Fork 116
ENH: run: Provide result record for command execution #6447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
After executing a command, yield a result record. This allows callers to control whether the save happens via the standard --on-failure switch. Note that this contains a breaking change: * it changes a CommandError to a result record with status="error" Suggested by @mih in dataladgh-3071.
Codecov Report
@@ Coverage Diff @@
## master #6447 +/- ##
=======================================
Coverage 89.97% 89.98%
=======================================
Files 348 348
Lines 43859 43867 +8
=======================================
+ Hits 39464 39474 +10
+ Misses 4395 4393 -2
Continue to review full report at Codecov.
|
|
FTR here how it looks in master with CommandError(git)lena:~datalad/datalad-master[master]git
$> python -c 'import datalad.api as dl; dl.Dataset("/tmp/testds").run("dokaboom"); print("Life is good")'
[INFO ] == Command start (output follows) =====
/bin/sh: 1: dokaboom: not found
[INFO ] == Command exit (modification check follows) =====
[INFO ] The command had a non-zero exit code. If this is expected, you can save the changes with "Dataset('/tmp/testds').save(path='.', recursive=True, message_file='.git/COMMIT_EDITMSG')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/yoh/proj/datalad/datalad-master/datalad/distribution/dataset.py", line 502, in apply_func
return f(*args, **kwargs)
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 436, in eval_func
return return_func(*args, **kwargs)
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 428, in return_func
results = list(results)
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 346, in generator_func
for r in _process_results(
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 543, in _process_results
for res in results:
File "/home/yoh/proj/datalad/datalad-master/datalad/core/local/run.py", line 299, in __call__
for r in run_command(cmd, dataset=dataset,
File "/home/yoh/proj/datalad/datalad-master/datalad/core/local/run.py", line 850, in run_command
raise exc
File "/home/yoh/proj/datalad/datalad-master/datalad/core/local/run.py", line 591, in _execute_command
runner.run(
File "/home/yoh/proj/datalad/datalad-master/datalad/runner/runner.py", line 201, in run
raise CommandError(
datalad.runner.exception.CommandError: CommandError: 'dokaboom' failed with exitcode 127 under /tmp/testds
and here with IncompleteResultsError(git)lena:~datalad/datalad-master[nf-runresult]git
$> python -c 'import datalad.api as dl; dl.Dataset("/tmp/testds").run("dokaboom"); print("Life is good")'
[INFO ] == Command start (output follows) =====
/bin/sh: 1: dokaboom: not found
[INFO ] == Command exit (modification check follows) =====
[INFO ] The command had a non-zero exit code. If this is expected, you can save the changes with "Dataset('/tmp/testds').save(path='.', recursive=True, message_file='.git/COMMIT_EDITMSG')"
run(error): /tmp/testds (dataset) [Executed command]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/yoh/proj/datalad/datalad-master/datalad/distribution/dataset.py", line 502, in apply_func
return f(*args, **kwargs)
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 437, in eval_func
return return_func(*args, **kwargs)
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 429, in return_func
results = list(results)
File "/home/yoh/proj/datalad/datalad-master/datalad/interface/utils.py", line 414, in generator_func
raise IncompleteResultsError(
datalad.support.exceptions.IncompleteResultsError: Command did not complete successfully. 1 failed:
[{'action': 'run',
'exception': CommandError(''),
'exception_traceback': '[run.py:_execute_command:610,runner.py:run:201]',
'exit_code': 127,
'explicit_outputs': None,
'message': 'Executed command',
'msg_path': '/tmp/testds/.git/COMMIT_EDITMSG',
'path': '/tmp/testds',
'record_id': None,
'run_info': {'chain': [],
'cmd': 'dokaboom',
'dsid': 'c8e4f9b8-ad5e-450f-b956-d3796ce54edb',
'exit': 127,
'extra_inputs': [],
'inputs': [],
'outputs': [],
'pwd': '.'},
'status': 'error',
'type': 'dataset'}]
|
|
Code Climate has analyzed commit c9518d1 and detected 1 issue on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
|
I added another changelog item with more details on the nature of the breaking change. |
Note that this contains a breaking change:
As pointed out in #3071 (comment) we could continue to raise a CommandError for Python-API users. But @mih is not convinced that this is worth it.
This is the last piece from the closed #5695
Demo:
TODO:
exit_code)Changelog
💫 Enhancements and new features
runnow yields a result record immediately after executing a command. This allows callers to use the standard--on-failure switchto control whether dataset modifications will be saved for a command that exited with an error. Fixes Option to force run (or containers-run) to save even if {cmd} exits with non-0 #3071🪓 Deprecations and removals
runno longer raises aCommandErrorexception for failed commands, but yields anerrorresult that includes a superset of the information provided by the exception. This change impacts command line usage insofar as the exit code of the underlying command is no longer relayed as the exit code of theruncommand call -- althoughruncontinues to exit with a non-zero exit code in case of an error. For Python API users, the nature of the raised exception changes fromCommandErrortoIncompleteResultsError, and the exception handling is now configurable using the standardon_failurecommand argument. The originalCommandErrorexception remains available via theexceptionproperty of the newly introduced result record for the command execution, and this result record is available viaIncompleteResultsError.failed, if such an exception is raised.