From 0972cb9987393e245717cb922932217fb58471a0 Mon Sep 17 00:00:00 2001 From: Branch Vincent Date: Sun, 27 Feb 2022 01:01:06 -0500 Subject: [PATCH] fix(run): improve error when command not found --- src/poetry/console/commands/run.py | 6 +++++- tests/console/commands/test_run.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/poetry/console/commands/run.py b/src/poetry/console/commands/run.py index 9a02e375125..071909d0fb0 100644 --- a/src/poetry/console/commands/run.py +++ b/src/poetry/console/commands/run.py @@ -29,7 +29,11 @@ def handle(self) -> Any: if scripts and script in scripts: return self.run_script(scripts[script], args) - return self.env.execute(*args) + try: + return self.env.execute(*args) + except FileNotFoundError: + self.line_error(f"Command not found: {script}") + return 1 @property def _module(self) -> "Module": diff --git a/tests/console/commands/test_run.py b/tests/console/commands/test_run.py index d71e35fbd57..1f062984d68 100644 --- a/tests/console/commands/test_run.py +++ b/tests/console/commands/test_run.py @@ -37,3 +37,14 @@ def test_run_keeps_options_passed_before_command( app_tester.application.long_version + "\n" ) assert [] == env.executed + + +def test_run_has_helpful_error_when_command_not_found( + app_tester: "ApplicationTester", env: "MockEnv" +): + env._execute = True + app_tester.execute("run nonexistent-command") + + assert env.executed == [["nonexistent-command"]] + assert app_tester.status_code == 1 + assert app_tester.io.fetch_error() == "Command not found: nonexistent-command\n"