Skip to content

Commit 37b3ff5

Browse files
committed
Handle :compile.file/2 returning :error on OTP 24
Before OTP 24 when given invalid args, :compile.file/2 would return: iex(1)> :compile.file('a.erl', [{:d, 'foo', 'bar'}, :report]) {:error, :badarg} On OTP 24: iex(1)> :compile.file('a.erl', [{:d, 'foo', 'bar'}, :report]) *** Internal compiler error *** exception error: bad argument in function io_lib:format/2 called as io_lib:format("badly formed '~s'",[{"foo","bar"}]) in call from sys_messages:list_errors/3 (sys_messages.erl, line 53) in call from lists:foreach/2 (lists.erl, line 1342) in call from compile:comp_ret_err/1 (compile.erl, line 546) in call from compile:'-internal_fun/2-anonymous-0-'/2 (compile.erl, line 229) in call from compile:'-do_compile/2-anonymous-0-'/1 (compile.erl, line 219) :error
1 parent b17d3a6 commit 37b3ff5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/mix/lib/mix/tasks/compile.erlang.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ defmodule Mix.Tasks.Compile.Erlang do
100100
file = Erlang.to_erl_file(Path.rootname(input, ".erl"))
101101

102102
case :compile.file(file, erlc_options) do
103-
{:error, :badarg} ->
103+
# TODO: Don't handle {:error, :badarg} when we require OTP 24
104+
error when error == :error or error == {:error, :badarg} ->
104105
message =
105-
"Compiling Erlang #{inspect(file)} failed with ArgumentError, probably because of invalid :erlc_options"
106+
"Compiling Erlang file #{inspect(file)} failed, probably because of invalid :erlc_options"
106107

107108
Mix.raise(message)
108109

lib/mix/test/mix/tasks/compile.erlang_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Mix.Tasks.Compile.ErlangTest do
1414
@tag erlc_options: [{:d, 'foo', 'bar'}]
1515
test "raises on invalid erlc_options" do
1616
in_fixture("compile_erlang", fn ->
17-
assert_raise Mix.Error, ~r"failed with ArgumentError", fn ->
17+
assert_raise Mix.Error, ~r"Compiling Erlang file '.*' failed", fn ->
1818
capture_io(fn ->
1919
Mix.Tasks.Compile.Erlang.run([])
2020
end)

0 commit comments

Comments
 (0)