Fix dialyzer type errors in coordinate validation

- Remove redundant nil check for callsign (spec guarantees String.t())
- Simplify coordinate validation by removing faulty infinity checks
- Remove unreachable catch-all clause in has_weather_packets?

Floats cannot equal atoms :infinity or :neg_infinity in Elixir.
Range checks already ensure finite values, making explicit infinity
checks unnecessary. Reduces dialyzer errors from 40 to 34.
This commit is contained in:
Graham McIntire 2026-02-20 18:17:47 -06:00
parent c34c233119
commit d22fc7c661
No known key found for this signature in database
2 changed files with 5 additions and 13 deletions

View file

@ -64,7 +64,7 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
callsign = generate_callsign(packet)
# Validate coordinates and callsign before building packet data
if valid_coordinates?(lat, lon) && callsign != "" && callsign != nil do
if valid_coordinates?(lat, lon) && callsign != "" do
packet_data = build_packet_map(packet, to_float(lat), to_float(lon), data_extended, locale)
Map.put(packet_data, "is_most_recent_for_callsign", is_most_recent_for_callsign)
else
@ -161,15 +161,12 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
# Validate coordinates are numeric and within valid ranges
@spec valid_coordinates?(any(), any()) :: boolean()
defp valid_coordinates?(lat, lon) when is_number(lat) and is_number(lon) do
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180 and
is_finite(lat) and is_finite(lon)
# Range checks ensure finite values; infinity would be outside these ranges
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180
end
defp valid_coordinates?(_, _), do: false
defp is_finite(n) when is_float(n), do: n != :infinity and n != :neg_infinity
defp is_finite(n) when is_integer(n), do: true
@doc """
Build packet data list for historical display.
Moved from historical_loader.ex.
@ -525,8 +522,6 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
_ -> false
end
defp has_weather_packets?(_), do: false
@spec convert_tuples_to_strings(any()) :: any()
defp convert_tuples_to_strings(map) when is_map(map) do
# Avoid processing structs entirely

View file

@ -445,14 +445,11 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
socket
end
defp is_finite(n) when is_float(n), do: n != :infinity and n != :neg_infinity
defp is_finite(n) when is_integer(n), do: true
defp packet_has_valid_coordinates?(packet) do
{lat, lon, _} = CoordinateUtils.get_coordinates(packet)
# Range checks ensure finite values; infinity would be outside these ranges
is_number(lat) and is_number(lon) and
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180 and
is_finite(lat) and is_finite(lon)
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180
end
end