Skip to content

Commit f13ae18

Browse files
committed
Show correct error if mix task could not be found
1 parent 29ebae3 commit f13ae18

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/mix/lib/mix/cli.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ defmodule Mix.CLI do
5858

5959
# If the task is not available, let's try to
6060
# compile the repository and then run it again.
61-
if Mix.Task.get(name) do
62-
Mix.Task.run(name, args)
63-
else
64-
Mix.Task.run("compile")
65-
Mix.Task.run(name, args)
61+
cond do
62+
Mix.Task.get(name) ->
63+
Mix.Task.run(name, args)
64+
Mix.Project.get ->
65+
Mix.Task.run("compile")
66+
Mix.Task.run(name, args)
67+
true ->
68+
# Raise no task error
69+
Mix.Task.get!(name)
6670
end
6771
rescue
6872
# We only rescue exceptions in the mix namespace, all

lib/mix/test/mix/cli_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ defmodule Mix.CLITest do
5151
end
5252
end
5353

54+
test "no task error" do
55+
in_fixture "no_mixfile", fn ->
56+
contents = mix("no_task")
57+
assert contents =~ "** (Mix) The task no_task could not be found\n"
58+
end
59+
end
60+
5461
test "--help smoke test" do
5562
in_fixture "only_mixfile", fn ->
5663
output = mix "--help"

0 commit comments

Comments
 (0)