View Source CredoCheckErrorHandlingEctoOban.Check.TransactionErrorInObanJob (CredoCheckErrorHandlingEctoOban v0.9.1)

This check has a base priority of normal and works with any version of Elixir.

explanation

Explanation

Ecto.Repo.transaction/2 will return a 4 tuple when an error occurs inside a Multi, per https://hexdocs.pm/ecto/Ecto.Repo.html#c:transaction/2

Below is the warning that Oban gives when this happens in iex

iex(14)> [warning] Expected Elixir.MyApp.MultiFailure.perform/1 to return:

  • :ok
  • :discard
  • {:ok, value}
  • {:error, reason},
  • {:cancel, reason}
  • {:discard, reason}
  • {:snooze, seconds} Instead received: {:error, :alas, :poor_yorick, %{}}

The job will be considered a success.


Here is an example of the potential situation:

def perform(%{}) do
  Multi.new()
  |> Multi.error(:alas, :poor_yorick)
  |> Repo.transaction()
end

Here is an example of the possible resolution (mapping the 4 tuple to a 2 tuple):

def perform(%{}) do
  Multi.new()
  |> Multi.error(:alas, :poor_yorick)
  |> Repo.transaction()
  |> case do
       {:ok, _} -> :ok
       {:error, :alas, _, _} -> {:error, "we knew him well"}
     end
end

check-specific-parameters

Check-Specific Parameters

There are no specific parameters for this check.

general-parameters

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.