Fix ParseError Access behavior error in packet batch insert

Fixed "ParseError does not implement the Access behaviour" error that
occurred during packet batch insert when packets contained ParseError
structs in their data_extended field.

Added special handling for Aprs.Types.ParseError structs in the
struct_to_map function to convert them to simple maps with their
error_code and message fields, preventing the Access behavior error
when the struct is accessed during processing.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-20 08:48:26 -05:00
parent 437cddfd51
commit 7db864bb64
No known key found for this signature in database

View file

@ -5,6 +5,7 @@ defmodule Aprsme.PacketConsumer do
"""
use GenStage
alias Aprs.Types.ParseError
alias Aprsme.LogSanitizer
alias Aprsme.Repo
@ -476,6 +477,15 @@ defmodule Aprsme.PacketConsumer do
defp normalize_data_type(attrs), do: Aprsme.EncodingUtils.normalize_data_type(attrs)
defp struct_to_map(%{__struct__: ParseError} = error) do
# Handle ParseError specially to avoid Access behavior issues
%{
error_code: error.error_code,
message: error.message,
__original_struct__: ParseError
}
end
defp struct_to_map(%{__struct__: struct_type} = struct) do
converted_map =
struct