diff --git a/lib/mix/tasks/compile.elixir_make.ex b/lib/mix/tasks/compile.elixir_make.ex index 8c8e969..bcc1dfa 100644 --- a/lib/mix/tasks/compile.elixir_make.ex +++ b/lib/mix/tasks/compile.elixir_make.ex @@ -231,16 +231,20 @@ defmodule Mix.Tasks.Compile.ElixirMake do {:ok, target, nif_version_to_use, url} -> archived_fullpath = Artefact.archive_path(config, target, nif_version_to_use) - unless File.exists?(archived_fullpath) do - Mix.shell().info("Downloading precompiled NIF to #{archived_fullpath}") + download = + unless File.exists?(archived_fullpath) do + Mix.shell().info("Downloading precompiled NIF to #{archived_fullpath}") - with {:ok, archived_data} <- Artefact.download(config, url) do - File.mkdir_p(Path.dirname(archived_fullpath)) - File.write(archived_fullpath, archived_data) + with {:ok, archived_data} <- Artefact.download(config, url) do + File.mkdir_p(Path.dirname(archived_fullpath)) + File.write(archived_fullpath, archived_data) + end end - end - Artefact.verify_and_decompress(archived_fullpath, app_priv) + case download do + {:error, _} = error -> error + _ -> Artefact.verify_and_decompress(archived_fullpath, app_priv) + end {:error, msg} -> {:error, msg} diff --git a/test/mix/tasks/compile.make_test.exs b/test/mix/tasks/compile.make_test.exs index ef2342d..00d8310 100644 --- a/test/mix/tasks/compile.make_test.exs +++ b/test/mix/tasks/compile.make_test.exs @@ -421,6 +421,29 @@ defmodule Mix.Tasks.Compile.ElixirMakeTest do end) end + test "surfaces the download error instead of a misleading file-not-found" do + in_fixture(fn -> + File.mkdir!("priv") + + File.write("Makefile", """ + all: + \t@touch priv/my_app + """) + + with_project_config( + [ + make_precompiler: {:nif, MyApp.Precompiler}, + make_precompiler_url: "https://example.com/@{artefact_filename}", + make_precompiler_downloader: MyApp.FailingDownloader + ], + fn -> + System.put_env("ELIXIR_MAKE_CACHE_DIR", "./cache") + assert capture_io(:stderr, fn -> run([]) end) =~ "download boom" + end + ) + end) + end + defp in_fixture(fun) do File.cd!(@fixture_project, fun) end @@ -440,3 +463,10 @@ defmodule MyApp.Downloader do File.read(path) end end + +defmodule MyApp.FailingDownloader do + @behaviour ElixirMake.Downloader + + @impl true + def download(_url), do: {:error, "download boom"} +end