Skip to content

Commit

Permalink
fix(core): fail gracefully when running non-existing commands (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Dec 9, 2021
1 parent af1f3b0 commit 2879c55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions renku/core/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ def _run_command(

started_at_time = local_now()

return_code = call(
factory.command_line, cwd=os.getcwd(), **{key: getattr(sys, key) for key in mapped_std.keys()}
)
try:
return_code = call(
factory.command_line, cwd=os.getcwd(), **{key: getattr(sys, key) for key in mapped_std.keys()}
)
except FileNotFoundError:
command = " ".join(factory.base_command)
raise errors.ParameterError(f"Cannot execute command '{command}'")

ended_at_time = local_now()

Expand Down
8 changes: 8 additions & 0 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,11 @@ def test_run_argument_parameters(runner, client, client_database_injection_manag
result = runner.invoke(cli, ["graph", "export", "--format", "jsonld", "--strict"])

assert 0 == result.exit_code, format_result_exception(result)


def test_run_non_existing_command(runner, client):
"""Test run with a non-existing command."""
result = runner.invoke(cli, ["run", "non-existing_command"])

assert 2 == result.exit_code
assert "Cannot execute command 'non-existing_command'" in result.output

0 comments on commit 2879c55

Please sign in to comment.