Skip to content

Commit

Permalink
Resolve commands that contain arguments correctly to output an error …
Browse files Browse the repository at this point in the history
…message

Commands like `git diff`, `verdi status` or `python script.py` will fail
with different opaque error messages, because only the first argument of
the command is resolved. With this PR the whole command is resolved
improving the error messages.
  • Loading branch information
agoscinski committed Sep 10, 2024
1 parent 521a7ec commit a3b6b97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aiida_shell/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def prepare_code(command: str, computer: Computer | None = None, resolve_command

if resolve_command:
with computer.get_transport() as transport:
status, stdout, stderr = transport.exec_command_wait(f'which {command}')
status, stdout, stderr = transport.exec_command_wait(f'which "{command}"')
executable = stdout.strip()

if status != 0:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def test_error_command_failed():
assert node.exit_status == ShellJob.exit_codes.ERROR_COMMAND_FAILED.status


def test_multi_command_raise():
"""Test :func:`aiida_shell.launch_shell_job` raises if ``command`` is passed with arguments.
Tests if the command is correctly resolved and raises an error message.
"""
with pytest.raises(ValueError, match=r'failed to determine the absolute path of the command on the computer.*'):
launch_shell_job('git diff')


def test_default():
"""Test :func:`aiida_shell.launch_shell_job` with default arguments."""
results, node = launch_shell_job('date')
Expand Down

0 comments on commit a3b6b97

Please sign in to comment.