Rework of d61fbd3's dialyzer suppression: the 4 warnings from
LiveTable.LiveResource's macro expansion are now fixed at the
root rather than hidden via .dialyzer_ignore.exs.
Changes:
- Delete .dialyzer_ignore.exs and remove ignore_warnings from
mix.exs. No more hidden suppressions.
- New MicrowavepropWeb.LiveTableResource shim that wraps
use LiveTable.LiveResource and overrides:
* maybe_subscribe/1 — explicit :ok = on Phoenix.PubSub.subscribe/2
(previously discarded, tripping :unmatched_return).
* handle_info/2 — explicit _ = on File.rm, Process.send_after.
Switch all 4 LiveTable-using LiveViews (contact_live/index,
beacon_live/index, admin/contact_edit_live, user_management_live/index)
to use MicrowavepropWeb.LiveTableResource instead.
- New priv/dep_patches/live_table-0.4.1.patch adds _ = in front of
LiveTable.LiveSelectHelpers.restore_live_select_from_params/2 in
the dep's macro-expanded handle_params/3. The call's return was
silently discarded, tripping the fourth warning per LiveView.
- New lib/mix/tasks/deps.patch.ex applies every
priv/dep_patches/*.patch to its target dep idempotently after
mix deps.get. Wired into the :setup alias + overridden
mix deps.get so the patch survives cache regeneration in CI.
- Other modified files in this commit are the spec-coverage
additions from the parallel agent pass (beacons.ex,
commercial.ex, propagation.ex, weather.ex, narr_client.ex,
run_timing.ex, 3 workers) — tighter specs for bounds, tuple
shapes, schema-typed params. Dialyzer remains at 0 after
the changes.
Upstream TODO: send a PR for the live_table `_ =` fix. Once
merged and released, drop the patch + mix task + bump the dep.
mix dialyzer --format short | grep ^lib/ | wc -l -> 0
mix test: 2165 tests, 2 pre-existing flakes (MapLive timestamp +
PropagationPrune ScoresFile), 0 regressions.
84 lines
2.9 KiB
Elixir
84 lines
2.9 KiB
Elixir
defmodule MicrowavepropWeb.LiveTableResource do
|
|
@moduledoc """
|
|
Thin wrapper around `LiveTable.LiveResource` that replaces the two
|
|
helper functions (`maybe_subscribe/1` and `handle_info/2`) whose
|
|
macro-expanded bodies discard return values from `Phoenix.PubSub.subscribe/2`,
|
|
`File.mkdir_p!/1`, `File.cp!/2`, `File.rm/1`, and `Process.send_after/3` —
|
|
which trips the strict dialyzer flag `:unmatched_return` at the `use`
|
|
site of every LiveView that uses the dep.
|
|
|
|
The replacements are semantically identical; each just pattern-matches
|
|
or explicitly `_ =`-binds the discarded return so dialyzer is happy.
|
|
No functional change.
|
|
|
|
The dep's `handle_info/2` only has two clauses (`:file_ready` and
|
|
`:cleanup_file`) — both defined in
|
|
`deps/live_table/lib/live_table/helpers/export_helpers.ex`. Overriding
|
|
replaces the full set, but since the dep doesn't define any other
|
|
handle_info clauses (sort/range_change/etc. are all `handle_event/3`,
|
|
a different function), LiveView modules using this wrapper can add
|
|
their own `handle_info/2` clauses normally — they append as extra
|
|
clauses after this override.
|
|
|
|
Upstream fix opportunity: submit a PR to
|
|
https://github.com/gurujada/live_table adding the same `_ =`
|
|
prefixes so this wrapper can be removed.
|
|
"""
|
|
|
|
defmacro __using__(opts) do
|
|
quote location: :keep do
|
|
use LiveTable.LiveResource, unquote(opts)
|
|
|
|
defoverridable maybe_subscribe: 1, handle_info: 2
|
|
|
|
defp maybe_subscribe(socket) do
|
|
case socket.assigns[:export_topic] do
|
|
nil ->
|
|
client_id = Ecto.UUID.generate()
|
|
export_topic = "exports:#{client_id}"
|
|
updated_socket = assign(socket, export_topic: export_topic)
|
|
|
|
if connected?(socket) do
|
|
:ok =
|
|
Phoenix.PubSub.subscribe(
|
|
Application.fetch_env!(:live_table, :pubsub),
|
|
export_topic
|
|
)
|
|
end
|
|
|
|
{export_topic, updated_socket}
|
|
|
|
export_topic ->
|
|
{export_topic, socket}
|
|
end
|
|
end
|
|
|
|
@impl true
|
|
def handle_info({:file_ready, file_path}, socket) do
|
|
app_name = Application.fetch_env!(:live_table, :app)
|
|
static_path = Path.join([:code.priv_dir(app_name), "static", "exports"])
|
|
File.mkdir_p!(static_path)
|
|
|
|
filename = Path.basename(file_path)
|
|
dest_path = Path.join(static_path, filename)
|
|
File.cp!(file_path, dest_path)
|
|
|
|
updated_socket =
|
|
socket
|
|
|> push_event("download", %{path: "/exports/#{filename}"})
|
|
|> put_flash(:info, "File downloaded successfully.")
|
|
|
|
_timer_ref =
|
|
Process.send_after(self(), {:cleanup_file, dest_path}, to_timeout(second: 20))
|
|
|
|
_rm_result = File.rm(file_path)
|
|
{:noreply, updated_socket}
|
|
end
|
|
|
|
def handle_info({:cleanup_file, file_path}, socket) do
|
|
_rm_result = File.rm(file_path)
|
|
{:noreply, socket}
|
|
end
|
|
end
|
|
end
|
|
end
|