Skip to content

Commit c9fbbac

Browse files
alcoJosé Valim
authored andcommitted
Add version checks and proper error formatting to escripts. Closes #2709
Signed-off-by: José Valim <[email protected]>
1 parent 98e1b4c commit c9fbbac

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/mix/lib/mix/tasks/escript.build.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,23 @@ defmodule Mix.Tasks.Escript.Build do
284284

285285
defp main_body_for(:elixir) do
286286
quote do
287+
erl_version = :erlang.system_info(:otp_release)
288+
case :string.to_integer(erl_version) do
289+
{num, _} when is_integer(num) and num >= 17 -> nil
290+
_ ->
291+
io_error ["Incompatible Erlang/OTP release: ", erl_version,
292+
".\nThis escript requires at least Erlang/OTP 17.0.\n"]
293+
:erlang.halt(1)
294+
end
295+
287296
case :application.ensure_all_started(:elixir) do
288297
{:ok, _} ->
289298
load_config(@config)
290299
start_app(@app)
291300
args = Enum.map(args, &List.to_string(&1))
292301
Kernel.CLI.run fn _ -> @module.main(args) end, true
293-
_ ->
294-
:io.put_chars :standard_error, "Elixir is not available, aborting.\n"
302+
error ->
303+
io_error ["Failed to start Elixir.\n", :io_lib.format('error: ~p~n', [error])]
295304
:erlang.halt(1)
296305
end
297306
end

0 commit comments

Comments
 (0)