-
Notifications
You must be signed in to change notification settings - Fork 38
Dialyzer reports unknown_function for ErrorTracker.Web.Hooks.SetAssigns.on_mount/4 #172
Description
Describe the bug
Dialyzer reports unknown_function for ErrorTracker.Web.Hooks.SetAssigns.on_mount/4 when using error_tracker_dashboard/2 in a router. This is because the function only defines a single clause with pattern matching on the first argument, and dialyzer can't verify the call will match.
To Reproduce
Steps to reproduce the behavior:
- Add
use ErrorTracker.Web, :routeranderror_tracker_dashboard("/errors")to a Phoenix router - Run
mix dialyzer - See error:
lib/myapp_web/router.ex:1:unknown_function Function ErrorTracker.Web.Hooks.SetAssigns.on_mount/4 does not exist.
Expected behavior
Dialyzer should pass without warnings for standard ErrorTracker usage.
Screenshots
N/A
Additional context
The issue is in lib/error_tracker/web/hooks/set_assigns.ex:
def on_mount({:set_dashboard_path, path}, _params, session, socket) do
# ...
end
This only defines one clause that pattern matches on {:set_dashboard_path, path}. Dialyzer can't prove calls to this function will match this pattern, so it reports the function as non-existent.
A catch-all clause would fix this:
def on_mount({:set_dashboard_path, path}, _params, session, socket) do
socket = %{socket | private: Map.put(socket.private, :dashboard_path, path)}
{:cont, assign(socket, csp_nonces: session["csp_nonces"])}
end
def on_mount(_name, _params, _session, socket) do
{:cont, socket}
end
Environment:
- error_tracker: 0.8.0
- Elixir: 1.18.1