Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<error>Command not found: <c1>{script}</c1></error>")
return 1

@property
def _module(self) -> "Module":
Expand Down
11 changes: 11 additions & 0 deletions tests/console/commands/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"