jackjoe / mailgun_logger

Simple Mailgun log persistence in Phoenix/Elixir
MIT License
74 stars 10 forks source link

Error during import #4

Closed robjenman closed 4 years ago

robjenman commented 4 years ago

Hi,

During import it loops over the pagination for some time before we get:

10:28:44.175 [error] Task #PID<0.3726.0> started from #PID<0.3727.0> terminating

** (FunctionClauseError) no function clause matching in MailgunLogger.Events.prepare_raw/2

(mailgun_logger 0.0.3) lib/mailgun_logger/events/events.ex:94: MailgunLogger.Events.prepare_raw(%{"delivery-status" => %{"bounce-code" => "4.4.1", "code" => 550, "description" => "This is the mail system at host xxxx@yyyy.\r\n\r\nI'm sorry to have to inform you that your message could not\r\nbe delivered to one or more recipients. It's attached below.\r\n\r\nFor further assistance, please send mail to postmaster.\r\n\r\nIf you do so, please include this problem report. You can\r\ndelete your own text from the attached returned message.\r\n\r\n The mail system\r\n\r\nxxxx@yyyy: delivery temporarily suspended: connect to\r\n xxxx@yyyy[195.105.217.14]:25: Connection refused\r\n", "message" => "X-Postfix; delivery temporarily suspended: connect to xxxx@yyyy[195.105.217.14]:25: Connection refused"}, "event" => "failed", "flags" => %{"is-delayed-bounce" => true}, "id" => "2owk2AOdTwC-sgXzCx0ZIA", "log-level" => "warn", "reason" => "bounce", "recipient" => "xxxx@yyyy", "severity" => "temporary", "timestamp" => 1597763806.283901}, 1)

(elixir 1.10.2) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2

(elixir 1.10.2) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2

(mailgun_logger 0.0.3) lib/mailgun_logger/events/events.ex:77: MailgunLogger.Events.save_events/2

(elixir 1.10.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2

(elixir 1.10.2) lib/task/supervised.ex:35: Task.Supervised.reply/5

(stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Function: #Function<2.1964153/0 in MailgunLogger.run/0>

Args: []

I can't see what in that particular event is causing the issue?

jeroenbourgois commented 4 years ago

Well, the struct passed to the function will not pattern match, as the error says. This is the payload for the first param:

  %{
    "delivery-status" => %{
      "bounce-code" => "4.4.1",
      "code" => 550,
      "description" =>
        "This is the mail system at host xxxx@yyyy.\r\n\r\nI'm sorry to have to inform you that your message could not\r\nbe delivered to one or more recipients. It's attached below.\r\n\r\nFor further assistance, please send mail to postmaster.\r\n\r\nIf you do so, please include this problem report. You can\r\ndelete your own text from the attached returned message.\r\n\r\n The mail system\r\n\r\nxxxx@yyyy: delivery temporarily suspended: connect to\r\n xxxx@yyyy[195.105.217.14]:25: Connection refused\r\n",
      "message" =>
        "X-Postfix; delivery temporarily suspended: connect to xxxx@yyyy[195.105.217.14]:25: Connection refused"
    },
    "event" => "failed",
    "flags" => %{"is-delayed-bounce" => true},
    "id" => "2owk2AOdTwC-sgXzCx0ZIA",
    "log-level" => "warn",
    "reason" => "bounce",
    "recipient" => "xxxx@yyyy",
    "severity" => "temporary",
    "timestamp" => 1_597_763_806.283901
  }

The prepare_raw/2 method had the following head:

  def prepare_raw(%{"message" => message} = event, account_id) do

So it cannot match the passed struct. So far we have not had that issue... On way to handle it, is add another head for prepare_raw/2 matching for example the 'reason bounce' value, or a more generic fallback altogether that will just ignore that specific event.

What are your thoughts?

jeroenbourgois commented 4 years ago

Closing due to no activity.