fix: Handle atom format field from APRS parser

The APRS parser sometimes returns :unknown as an atom for the format field,
but the database expects a string. This was causing Ecto.ChangeError when
inserting packets.

Added normalize_format_field/1 function to convert atom values to strings
before database insertion. This ensures compatibility between the parser
output and database schema requirements.

Fixes error: value `:unknown` for `Aprsme.Packet.format` in `insert_all`
does not match type :string

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-08-01 17:04:32 -05:00
parent 86d3837075
commit 5ddbb18a10
No known key found for this signature in database

View file

@ -367,7 +367,7 @@ defmodule Aprsme.Packet do
)
|> maybe_put(:position_ambiguity, data_extended[:position_ambiguity] || data_extended["position_ambiguity"])
|> maybe_put(:posresolution, data_extended[:posresolution] || data_extended["posresolution"])
|> maybe_put(:format, data_extended[:format] || data_extended["format"])
|> maybe_put(:format, normalize_format_field(data_extended[:format] || data_extended["format"]))
end
defp put_weather_fields(map, data_extended) do
@ -720,4 +720,10 @@ defmodule Aprsme.Packet do
_ -> 0
end
end
# Normalize format field from atom to string
defp normalize_format_field(nil), do: nil
defp normalize_format_field(format) when is_atom(format), do: to_string(format)
defp normalize_format_field(format) when is_binary(format), do: format
defp normalize_format_field(_), do: nil
end