diff --git a/lib/federation/activity_pub/activity_pub.ex b/lib/federation/activity_pub/activity_pub.ex index 483f7c7d..824b9c3c 100644 --- a/lib/federation/activity_pub/activity_pub.ex +++ b/lib/federation/activity_pub/activity_pub.ex @@ -621,6 +621,10 @@ defmodule Mobilizon.Federation.ActivityPub do Logger.info("Actor was deleted") {:error, :actor_deleted} + {:error, e} -> + Logger.warn("Failed to make actor from url") + {:error, e} + e -> Logger.warn("Failed to make actor from url") {:error, e} @@ -801,6 +805,10 @@ defmodule Mobilizon.Federation.ActivityPub do Logger.info("Response HTTP 410") {:error, :actor_deleted} + {:error, e} -> + Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}") + {:error, e} + e -> Logger.warn("Could not decode actor at fetch #{url}, #{inspect(e)}") {:error, e} diff --git a/lib/federation/activity_pub/types/discussions.ex b/lib/federation/activity_pub/types/discussions.ex index f9b615d6..3f06baed 100644 --- a/lib/federation/activity_pub/types/discussions.ex +++ b/lib/federation/activity_pub/types/discussions.ex @@ -132,7 +132,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Discussions do ) args - |> Map.update(:title, "", &String.trim/1) + # title might be nil + |> Map.update(:title, "", fn title -> String.trim(title || "") end) |> Map.put(:text, text) end end diff --git a/lib/graphql/resolvers/user.ex b/lib/graphql/resolvers/user.ex index 467305b9..82a4dde3 100644 --- a/lib/graphql/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -115,7 +115,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do def create_user(_parent, args, _resolution) do with :registration_ok <- check_registration_config(args), {:ok, %User{} = user} <- Users.register(args), - {:ok, %Bamboo.Email{}} <- + %Bamboo.Email{} <- Email.User.send_confirmation_email(user, Map.get(args, :locale, "en")) do {:ok, user} else @@ -206,7 +206,7 @@ defmodule Mobilizon.GraphQL.Resolvers.User do Users.get_user_by_email(email, activated: true, unconfirmed: false), {:can_reset_password, true} <- {:can_reset_password, Authenticator.can_reset_password?(user)}, - {:ok, %Bamboo.Email{} = _email_html} <- + {:ok, %Bamboo.Email{}} <- Email.User.send_password_reset_email(user, Map.get(args, :locale, locale)) do {:ok, email} else diff --git a/lib/mobilizon.ex b/lib/mobilizon.ex index d07059dd..c754964a 100644 --- a/lib/mobilizon.ex +++ b/lib/mobilizon.ex @@ -16,7 +16,7 @@ defmodule Mobilizon do alias Mobilizon.{Config, Storage, Web} alias Mobilizon.Federation.ActivityPub - alias Mobilizon.Service.ErrorPage + alias Mobilizon.Service.{ErrorPage, ErrorReporter} alias Mobilizon.Service.Export.{Feed, ICalendar} @name Mix.Project.config()[:name] @@ -68,6 +68,14 @@ defmodule Mobilizon do Logger.add_backend(Sentry.LoggerBackend) :ok = Oban.Telemetry.attach_default_logger() + + :telemetry.attach_many( + "oban-errors", + [[:oban, :job, :exception], [:oban, :circuit, :trip]], + &ErrorReporter.handle_event/4, + %{} + ) + Supervisor.start_link(children, strategy: :one_for_one, name: Mobilizon.Supervisor) end diff --git a/lib/service/error_reporter.ex b/lib/service/error_reporter.ex new file mode 100644 index 00000000..46900d94 --- /dev/null +++ b/lib/service/error_reporter.ex @@ -0,0 +1,17 @@ +defmodule Mobilizon.Service.ErrorReporter do + @moduledoc """ + Module to delegate all exceptions to Sentry + """ + def handle_event([:oban, :job, :exception], measure, %{job: job} = meta, _) do + extra = + job + |> Map.take([:id, :args, :meta, :queue, :worker]) + |> Map.merge(measure) + + Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: extra) + end + + def handle_event([:oban, :circuit, :trip], _measure, meta, _) do + Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta) + end +end diff --git a/lib/web/email/mailer.ex b/lib/web/email/mailer.ex index 3b286834..4996f769 100644 --- a/lib/web/email/mailer.ex +++ b/lib/web/email/mailer.ex @@ -5,30 +5,26 @@ defmodule Mobilizon.Web.Email.Mailer do use Bamboo.Mailer, otp_app: :mobilizon def send_email_later(email) do - try do - Mobilizon.Web.Email.Mailer.deliver_later!(email) - rescue - error -> - Sentry.capture_exception(error, - stacktrace: __STACKTRACE__, - extra: %{extra: "Error while sending email"} - ) + Mobilizon.Web.Email.Mailer.deliver_later!(email) + rescue + error -> + Sentry.capture_exception(error, + stacktrace: __STACKTRACE__, + extra: %{extra: "Error while sending email"} + ) - reraise error, __STACKTRACE__ - end + reraise error, __STACKTRACE__ end def send_email(email) do - try do - Mobilizon.Web.Email.Mailer.deliver_now!(email) - rescue - error -> - Sentry.capture_exception(error, - stacktrace: __STACKTRACE__, - extra: %{extra: "Error while sending email"} - ) + Mobilizon.Web.Email.Mailer.deliver_now!(email) + rescue + error -> + Sentry.capture_exception(error, + stacktrace: __STACKTRACE__, + extra: %{extra: "Error while sending email"} + ) - reraise error, __STACKTRACE__ - end + reraise error, __STACKTRACE__ end end diff --git a/lib/web/email/user.ex b/lib/web/email/user.ex index 5f45d3e2..7dd74b70 100644 --- a/lib/web/email/user.ex +++ b/lib/web/email/user.ex @@ -80,7 +80,7 @@ defmodule Mobilizon.Web.Email.User do Users.update_user(user, %{ "confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second) }), - {:ok, %Bamboo.Email{}} <- send_confirmation_email(user, locale) do + %Bamboo.Email{} <- send_confirmation_email(user, locale) do Logger.info("Sent confirmation email again to #{user.email}") {:ok, user.email} end @@ -132,7 +132,7 @@ defmodule Mobilizon.Web.Email.User do "reset_password_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second) }) ), - {:ok, %Bamboo.Email{} = mail} <- + %Bamboo.Email{} = mail <- user_updated |> Email.User.reset_password_email(locale) |> Email.Mailer.send_email_later() do