Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of high and works with any version of Elixir.
Explanation
Flags start_async/3 calls whose name no handle_async/3 clause in
the same LiveView or LiveComponent accepts. When the task finishes,
LiveView calls handle_async/3 with that name, and the missing clause
crashes the process.
Before:
def mount(_params, _session, socket) do
{:ok, start_async(socket, :load_stats, fn -> Stats.load() end)}
end
def handle_async(:load_users, result, socket), do: ...After:
def handle_async(:load_stats, {:ok, stats}, socket), do: ...Names match when they are equal atoms or tuples with the same tag and
size; a handle_async(name, ...) catch-all accepts every name.
The check reads the compiled module's expanded AST, so it sees
handlers that use macros inject. Handlers attached with
attach_hook/4 (in the module or its on_mount hooks) make the
finding unverifiable; it appears only in strict mode.
Confidence: high. Tier: semantic (run mix compile before mix credo).
Check-Specific Parameters
Use the following parameters to configure this check:
:excluded_paths
Paths to skip (atoms, binaries as path segments, or regexes).
This parameter defaults to [~r/\/test\//, "test"].
:strict
Report unverifiable findings too.
This parameter defaults to false.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.