Skip to content

Commit

Permalink
prepare_code: Quote command when passing to which in order to res…
Browse files Browse the repository at this point in the history
…olve (#99)

The `command` was passed to `which` without being quoted. If the command
consists of multiple commands, which is not supported, each word would be
interpreted by `which` as a separate command, as it takes a number of commands
to resolved. This would result in a misleading error message. By quoting the
command, a multi command will correctly raise an error message for the user.
  • Loading branch information
agoscinski committed Sep 10, 2024
1 parent 521a7ec commit 104d03b
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 104d03b

Please sign in to comment.