-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
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"])) |
There was a problem hiding this comment.
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
lib/telemetry_metrics.ex
Outdated
@@ -9,6 +9,8 @@ defmodule Membrane.TelemetryMetrics do | |||
|
|||
@type label() :: list() | |||
|
|||
@dialyzer [{:nowarn_function, emit_event?: 1}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It would be best if you narrowed down the
:nowarn
to a flag disabling the specific warning - Such a thing requires a comment explaining why is this disabled
lib/telemetry_metrics.ex
Outdated
# 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}] |
There was a problem hiding this comment.
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
b21ba86
to
f0e208a
Compare
lib/telemetry_metrics.ex
Outdated
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 |
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this 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
lib/telemetry_metrics.ex
Outdated
# @enabled Application.compile_env(:membrane_telemetry_metrics, :enabled, false) | ||
# @events Application.compile_env(:membrane_telemetry_metrics, :events, :all) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# @enabled Application.compile_env(:membrane_telemetry_metrics, :enabled, false) | |
# @events Application.compile_env(:membrane_telemetry_metrics, :events, :all) |
Related ticket on Jira board: https://membraneframework.atlassian.net/browse/MS-217?atlOrigin=eyJpIjoiOWE5ZjA3MmIxMGIyNGYxM2E2ZmMzZjQ2OGFhMWI5ZTciLCJwIjoiaiJ9