From 5ddbb18a10006a0d53d0c11464a19b40bdc69911 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 1 Aug 2025 17:04:32 -0500 Subject: [PATCH] fix: Handle atom format field from APRS parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/aprsme/packet.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/aprsme/packet.ex b/lib/aprsme/packet.ex index 42df918..bc10e3a 100644 --- a/lib/aprsme/packet.ex +++ b/lib/aprsme/packet.ex @@ -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