Fix Sentry.Event struct access error in SentryFilter

Replace get_in/Access usage with proper struct pattern matching to fix
UndefinedFunctionError when accessing Sentry.Event fields. The struct
doesn't implement the Access behavior, so we now use pattern matching
and direct field access instead.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-24 19:21:23 -05:00
parent e84dcb6bc0
commit 01cf1ee478
No known key found for this signature in database

View file

@ -26,8 +26,15 @@ defmodule Aprsme.SentryFilter do
# Check if the event should be filtered out
defp should_filter_event?(event) do
error_type = get_in(event, [:exception, Access.at(0), :type])
error_message = get_in(event, [:exception, Access.at(0), :value])
# Access the first exception from the list if it exists
first_exception =
case event.exception do
[first | _] -> first
_ -> nil
end
error_type = if first_exception, do: first_exception.type
error_message = if first_exception, do: first_exception.value
cond do
# Filter out Bandit errors for missing Host header
@ -53,7 +60,11 @@ defmodule Aprsme.SentryFilter do
# Check if the request path looks like a bot/scanner
defp is_bot_path?(event) do
request_path = get_in(event, [:request, :url]) || ""
request_path =
case event.request do
%{url: url} when is_binary(url) -> url
_ -> ""
end
bot_patterns = [
~r/\.php$/i,
@ -78,8 +89,12 @@ defmodule Aprsme.SentryFilter do
# Extract a readable error description
defp inspect_error(event) do
error_type = get_in(event, [:exception, Access.at(0), :type]) || "Unknown"
error_message = get_in(event, [:exception, Access.at(0), :value]) || "No message"
# Access the first exception from the list if it exists
{error_type, error_message} =
case event.exception do
[%{type: type, value: value} | _] -> {type || "Unknown", value || "No message"}
_ -> {"Unknown", "No message"}
end
"#{error_type}: #{error_message}"
end