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 issues #4

Merged
merged 5 commits into from
Sep 26, 2022
Merged

Fix Dialyzer issues #4

merged 5 commits into from
Sep 26, 2022

Conversation

FelonEkonom
Copy link
Member

@FelonEkonom FelonEkonom added the bug Something isn't working label Sep 6, 2022
@FelonEkonom FelonEkonom requested a review from mat-hek September 6, 2022 10:13
@FelonEkonom FelonEkonom self-assigned this Sep 6, 2022
@FelonEkonom FelonEkonom linked an issue Sep 6, 2022 that may be closed by this pull request
mix.exs Outdated
@@ -52,6 +52,7 @@ defmodule Membrane.TelemetryMetrics.Mixfile do

if System.get_env("CI") == "true" do
# Store PLTs in cacheable directory for CI
File.mkdir_p!(Path.join([__DIR__, "priv", "plts"]))
Copy link
Member

Choose a reason for hiding this comment

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

This should not be needed, it's part of CI pipeline

@@ -9,6 +9,8 @@ defmodule Membrane.TelemetryMetrics do

@type label() :: list()

@dialyzer [{:nowarn_function, emit_event?: 1}]
Copy link
Member

Choose a reason for hiding this comment

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

  1. It would be best if you narrowed down the :nowarn to a flag disabling the specific warning
  2. Such a thing requires a comment explaining why is this disabled

Comment on lines 12 to 14
# Suppresses Dialyzer false-positive error occurring due to fact, that function contains match on module attribute known at compile time but can be overridden in the config file.
# Dialyzer returns an error saying, that pattern can never match the type, but it might be not true, in the case when somebody will change its value in the custom config file.
@dialyzer [{:no_match, emit_event?: 1}]
Copy link
Member

Choose a reason for hiding this comment

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

This description is way too verbose, but it can be removed altogether by simply fixing the error. Instead of defining a condition inside helper function, conditionally define the function and it seems to work, ensure it won't generate warnings in code using the macros here:

  cond do
    not @enabled -> defp emit_event?(_event), do: false
    @events == :all -> defp emit_event?(_event), do: true
    is_list(@events) -> defp emit_event?(event), do: event in @events
    true -> defp emit_event?(_event), do: false
  end

Comment on lines 87 to 91
cond do
not @enabled -> defp emit_event?(_event), do: false
@events == :all -> defp emit_event?(_event), do: true
is_list(@events) -> defp emit_event?(event), do: event in @events
true -> defp emit_event?(_event), do: false
Copy link
Member

Choose a reason for hiding this comment

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

I've told you to check for warnings 😛
When MIX_ENV=test it's fine (thus CI passes) but in dev when @enabled is false, there's a warning about unused module attribute.

I've found a way to solve it - use variables for code executed at compile time:

Suggested change
cond do
not @enabled -> defp emit_event?(_event), do: false
@events == :all -> defp emit_event?(_event), do: true
is_list(@events) -> defp emit_event?(event), do: event in @events
true -> defp emit_event?(_event), do: false
enabled = Application.compile_env(:membrane_telemetry_metrics, :enabled, false)
events = Application.compile_env(:membrane_telemetry_metrics, :events, :all)
cond do
not enabled -> defp emit_event?(_event), do: false
events == :all -> defp emit_event?(_event), do: true
is_list(events) -> defp emit_event?(event), do: event in events
true -> defp emit_event?(_event), do: false

Copy link
Member

@bblaszkow06 bblaszkow06 left a comment

Choose a reason for hiding this comment

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

Remove the leftovers and we're good to go

Comment on lines 7 to 8
# @enabled Application.compile_env(:membrane_telemetry_metrics, :enabled, false)
# @events Application.compile_env(:membrane_telemetry_metrics, :events, :all)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# @enabled Application.compile_env(:membrane_telemetry_metrics, :enabled, false)
# @events Application.compile_env(:membrane_telemetry_metrics, :events, :all)

@FelonEkonom FelonEkonom merged commit a46281f into master Sep 26, 2022
@FelonEkonom FelonEkonom deleted the fix-dialyzer-issues branch September 26, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ci circle lint fails ❌
2 participants