Skip to content

Commit

Permalink
fix: properly intercept thrown errors in Ash.bulk_create
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Apr 29, 2024
1 parent 69b5bd3 commit ca7b082
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ash/actions/create/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ defmodule Ash.Actions.Create.Bulk do

defp errors(result, {:error, error}, opts) do
if opts[:return_errors?] do
{result.error_count + 1, [error | result.errors]}
{result.error_count + 1, [error | result.errors || []]}
else
{result.error_count + 1, []}
end
Expand Down Expand Up @@ -758,7 +758,7 @@ defmodule Ash.Actions.Create.Bulk do

defp store_error(ref, error, opts) do
if opts[:stop_on_error?] && !opts[:return_stream?] do
throw({:error, Ash.Error.to_error_class(error), 0, []})
throw({:error, Ash.Error.to_error_class(error), 0})
else
if opts[:return_errors?] do
{errors, count} = Process.get({:bulk_create_errors, ref}) || {[], 0}
Expand Down Expand Up @@ -1412,7 +1412,7 @@ defmodule Ash.Actions.Create.Bulk do
changeset

{:error, error} ->
Ash.Changeset.add_error(changeset, error)
Ash.Changeset.add_error(changeset, validation.message || error)
end

true ->
Expand Down

0 comments on commit ca7b082

Please sign in to comment.