From ddae7b0af0b14ed1ea7f365d9e1424bf0bc7c1a2 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Tue, 25 Jun 2024 09:51:58 +0200 Subject: [PATCH 1/5] Remove ignored dialyzer warnings In order to fix the dialyzer warnings, remove each one from the ignore file. When all warnings are fixed, the ignore file could be removed altogether. --- dialyzer.ignore-warnings | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dialyzer.ignore-warnings b/dialyzer.ignore-warnings index 276a202eb..e69de29bb 100644 --- a/dialyzer.ignore-warnings +++ b/dialyzer.ignore-warnings @@ -1,6 +0,0 @@ -lib/appsignal/json.ex:31: Unknown function 'Elixir.Jason':encode/1 -lib/appsignal/json.ex:32: Unknown function 'Elixir.Jason':'encode!'/1 -lib/appsignal/json.ex:33: Unknown function 'Elixir.Jason':decode/1 -lib/appsignal/json.ex:34: Unknown function 'Elixir.Jason':'decode!'/1 -lib/mix/tasks/appsignal.install.ex:175: The pattern {'error', _reason@1} can never match the type 'ok' -lib/mix/tasks/appsignal.install.ex:190 From b5fcf2f1ac55550460a97396fe49f269a98f31a7 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Tue, 25 Jun 2024 09:55:11 +0200 Subject: [PATCH 2/5] Remove error handling for IO.binwrite Currently, the write_config_file/1 function in the installer checks the return value of a call to IO.binwrite/2. However, that function only ever returns :ok or raises an error when it fails to write. This patch removes the error handling, assuming the write works. Since the error handling is removed, the write will crash the installer if it fails, which is the intended bahavior. --- lib/mix/tasks/appsignal.install.ex | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/mix/tasks/appsignal.install.ex b/lib/mix/tasks/appsignal.install.ex index 02c0528fa..fc536011d 100644 --- a/lib/mix/tasks/appsignal.install.ex +++ b/lib/mix/tasks/appsignal.install.ex @@ -183,15 +183,8 @@ defmodule Mix.Tasks.Appsignal.Install do case File.open(appsignal_config_file_path(), [:write]) do {:ok, file} -> - case IO.binwrite(file, appsignal_config_file_contents(config)) do - :ok -> - IO.puts("Success!") - - {:error, reason} -> - IO.puts("Failure! #{inspect(reason)}") - exit(:shutdown) - end - + IO.binwrite(file, appsignal_config_file_contents(config)) + IO.puts("Success!") File.close(file) {:error, reason} -> From eba8a48c39c4266f830b3b3a880f5b79f91cfdfc Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Tue, 25 Jun 2024 10:19:10 +0200 Subject: [PATCH 3/5] Remove dialyzer.ignore-warnings Since removing all lines from Dialyzer's ignore file, the dialyzer.ignore-warnings file is no longer needed. --- dialyzer.ignore-warnings | 0 mix.exs | 1 - 2 files changed, 1 deletion(-) delete mode 100644 dialyzer.ignore-warnings diff --git a/dialyzer.ignore-warnings b/dialyzer.ignore-warnings deleted file mode 100644 index e69de29bb..000000000 diff --git a/mix.exs b/mix.exs index 3b8310b13..5716afc05 100644 --- a/mix.exs +++ b/mix.exs @@ -37,7 +37,6 @@ defmodule Appsignal.Mixfile do extras: ["README.md", "CHANGELOG.md"] ], dialyzer: [ - ignore_warnings: "dialyzer.ignore-warnings", plt_file: {:no_warn, "priv/plts/dialyzer.plt"}, plt_add_apps: [:mix] ] From 494a4d76678bc3f0d5d0ebf502e362a90627fdd5 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Tue, 25 Jun 2024 12:44:55 +0200 Subject: [PATCH 4/5] Handle binwrite failures in installer Since Elixir 1.16, the IO.binwrite/2 function no longer returns an :ok- or :error tuple. Instead, it simply raises an error when it fails. To keep compatibility with previous versions of Elixir, this patch implements binwrite_with_result, which is a delegate of IO.binwrite/2 on versions before 1.16, and a try-catch wrapper for Elixir 1.16 and above. With that function in place, the precious implementation is restored, which prints "Failure!" before the error message in the unlikely event that the write fails. --- lib/mix/tasks/appsignal.install.ex | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/mix/tasks/appsignal.install.ex b/lib/mix/tasks/appsignal.install.ex index fc536011d..abad39f89 100644 --- a/lib/mix/tasks/appsignal.install.ex +++ b/lib/mix/tasks/appsignal.install.ex @@ -183,6 +183,15 @@ defmodule Mix.Tasks.Appsignal.Install do case File.open(appsignal_config_file_path(), [:write]) do {:ok, file} -> + 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 + IO.binwrite(file, appsignal_config_file_contents(config)) IO.puts("Success!") File.close(file) @@ -193,6 +202,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 From fefa3c2c68fb63e08e80526d8d829cfacf4002db Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Tue, 25 Jun 2024 18:26:07 +0200 Subject: [PATCH 5/5] Update appsignal.install.ex Co-authored-by: Tom de Bruijn --- lib/mix/tasks/appsignal.install.ex | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mix/tasks/appsignal.install.ex b/lib/mix/tasks/appsignal.install.ex index abad39f89..5b62fa62e 100644 --- a/lib/mix/tasks/appsignal.install.ex +++ b/lib/mix/tasks/appsignal.install.ex @@ -192,8 +192,6 @@ defmodule Mix.Tasks.Appsignal.Install do exit(:shutdown) end - IO.binwrite(file, appsignal_config_file_contents(config)) - IO.puts("Success!") File.close(file) {:error, reason} ->