Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dialyzer warnings and remove ignore file #952

Merged
merged 5 commits into from
Jun 26, 2024
Merged

Conversation

jeffkreeftmeijer
Copy link
Member

Previously, the repository included a Dialyzer ignore file with a couple
of ignored warnings. This patch fixes all warnings and removes the file.

[skip changeset]

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.
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.
Since removing all lines from Dialyzer's ignore file, the
dialyzer.ignore-warnings file is no longer needed.
@unflxw
Copy link
Contributor

unflxw commented Jun 25, 2024

Did you see the conversation on Slack about the IO.binwrite error? I thought @luismiramirez's reasons for wanting to keep the error handling and ignoring the Dyalizer warning were solid. In short, doing so ensures the actual error message is shown on older Elixir versions, instead of some unrelated error about case clauses.

exit(:shutdown)
end

IO.binwrite(file, appsignal_config_file_contents(config))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@unflxw unflxw Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't fail, but it will silently swallow the error -- it needs to at least be :ok = IO.binwrite(...), for compatibility with older Elixir versions.

(but also, see the other comment, re: the error handling)

@jeffkreeftmeijer
Copy link
Member Author

I don't think this is an error that will actually happen. If we want to add error handling anyway, we should wrap the call in a try block because it either returns an :ok or raises an error. It looks like the current implementation won't do what we think it does.

@unflxw
Copy link
Contributor

unflxw commented Jun 25, 2024

The issue is that, in previous versions of Elixir (< 1.16), it does return {:error, reason} instead of raising.

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.
@jeffkreeftmeijer
Copy link
Member Author

Cool, then I propose this: 494a4d7

lib/mix/tasks/appsignal.install.ex Outdated Show resolved Hide resolved
Co-authored-by: Tom de Bruijn <[email protected]>
@jeffkreeftmeijer jeffkreeftmeijer merged commit a7ffd4e into main Jun 26, 2024
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants