Skip to content

Commit d1b31e2

Browse files
committed
fix(xref): raise on --min-cycle-label <= 0
Provides an error message in favor of ``` mix xref graph --format cycles --min-cycle-label 0 --label compile-connected ** (FunctionClauseError) no function clause matching in Enum.count_until/3 The following arguments were given to Enum.count_until/3: # 1 [{"lib/foo.ex", nil}, {"lib/bar.ex", nil}] # 2 #Function<4.83728021/1 in Mix.Tasks.Xref.cycle_filter_fn/1> # 3 0 Attempted function clauses (showing 1 out of 1): def count_until(enumerable, fun, limit) when is_integer(limit) and limit > 0 (elixir 1.19.4) lib/enum.ex:783: Enum.count_until/3 (mix 1.19.4) lib/mix/tasks/xref.ex:1247: anonymous fn/3 in Mi ```
1 parent fc747ff commit d1b31e2

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/mix/lib/mix/tasks/xref.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@ defmodule Mix.Tasks.Xref do
12381238
Mix.raise("--min-cycle-label requires the --label option to be given")
12391239
end
12401240

1241+
if integer <= 0 do
1242+
Mix.raise("--min-cycle-label must be greater than 0")
1243+
end
1244+
12411245
integer
12421246
else
12431247
1

lib/mix/test/mix/tasks/xref_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ defmodule Mix.Tasks.XrefTest do
579579
""")
580580
end
581581

582+
test "bad min_cycle_label" do
583+
assert_raise Mix.Error, "--min-cycle-label must be greater than 0", fn ->
584+
assert_graph(["--format", "cycles", "--label", "compile", "--min-cycle-label", "0"], "")
585+
end
586+
end
587+
582588
test "cycles with min_cycle_size greater than actual length" do
583589
assert_graph(["--format", "cycles", "--min-cycle-size", "3"], """
584590
No cycles found

0 commit comments

Comments
 (0)