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:
parent
c34c233119
commit
d22fc7c661
2 changed files with 5 additions and 13 deletions
|
|
@ -64,7 +64,7 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
|
||||||
callsign = generate_callsign(packet)
|
callsign = generate_callsign(packet)
|
||||||
|
|
||||||
# Validate coordinates and callsign before building packet data
|
# 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)
|
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)
|
Map.put(packet_data, "is_most_recent_for_callsign", is_most_recent_for_callsign)
|
||||||
else
|
else
|
||||||
|
|
@ -161,15 +161,12 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
|
||||||
# Validate coordinates are numeric and within valid ranges
|
# Validate coordinates are numeric and within valid ranges
|
||||||
@spec valid_coordinates?(any(), any()) :: boolean()
|
@spec valid_coordinates?(any(), any()) :: boolean()
|
||||||
defp valid_coordinates?(lat, lon) when is_number(lat) and is_number(lon) do
|
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
|
# Range checks ensure finite values; infinity would be outside these ranges
|
||||||
is_finite(lat) and is_finite(lon)
|
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180
|
||||||
end
|
end
|
||||||
|
|
||||||
defp valid_coordinates?(_, _), do: false
|
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 """
|
@doc """
|
||||||
Build packet data list for historical display.
|
Build packet data list for historical display.
|
||||||
Moved from historical_loader.ex.
|
Moved from historical_loader.ex.
|
||||||
|
|
@ -525,8 +522,6 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
|
||||||
_ -> false
|
_ -> false
|
||||||
end
|
end
|
||||||
|
|
||||||
defp has_weather_packets?(_), do: false
|
|
||||||
|
|
||||||
@spec convert_tuples_to_strings(any()) :: any()
|
@spec convert_tuples_to_strings(any()) :: any()
|
||||||
defp convert_tuples_to_strings(map) when is_map(map) do
|
defp convert_tuples_to_strings(map) when is_map(map) do
|
||||||
# Avoid processing structs entirely
|
# Avoid processing structs entirely
|
||||||
|
|
|
||||||
|
|
@ -445,14 +445,11 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
|
||||||
socket
|
socket
|
||||||
end
|
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
|
defp packet_has_valid_coordinates?(packet) do
|
||||||
{lat, lon, _} = CoordinateUtils.get_coordinates(packet)
|
{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
|
is_number(lat) and is_number(lon) and
|
||||||
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180 and
|
lat >= -90 and lat <= 90 and lon >= -180 and lon <= 180
|
||||||
is_finite(lat) and is_finite(lon)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue