Skip to content

Dialyzer reports unknown_function for ErrorTracker.Web.Hooks.SetAssigns.on_mount/4 #172

@markquezada

Description

@markquezada

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:

  1. Add use ErrorTracker.Web, :router and error_tracker_dashboard("/errors") to a Phoenix router
  2. Run mix dialyzer
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions