diff --git a/lib/mix/tasks/appsignal.install.ex b/lib/mix/tasks/appsignal.install.ex index fc536011..5b62fa62 100644 --- a/lib/mix/tasks/appsignal.install.ex +++ b/lib/mix/tasks/appsignal.install.ex @@ -183,8 +183,15 @@ defmodule Mix.Tasks.Appsignal.Install do case File.open(appsignal_config_file_path(), [:write]) do {:ok, file} -> - IO.binwrite(file, appsignal_config_file_contents(config)) - IO.puts("Success!") + case binwrite_with_result(file, appsignal_config_file_contents(config)) do + :ok -> + IO.puts("Success!") + + {:error, reason} -> + IO.puts("Failure! #{inspect(reason)}") + exit(:shutdown) + end + File.close(file) {:error, reason} -> @@ -193,6 +200,18 @@ defmodule Mix.Tasks.Appsignal.Install do end end + if Version.match?(System.version(), ">= 1.16.0") do + defp binwrite_with_result(path, contents) do + try do + IO.binwrite(path, contents) + catch + {:error, reason} -> {:error, reason} + end + end + else + defdelegate binwrite_with_result(path, contents), to: IO, as: :binwrite + end + # Link the config/appsignal.exs config file to the config/config.exs file. # If already linked, it's ignored. defp link_config_file do