From aa1f902c5093664a30d00e473881b2d8b432ce8e Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 5 Jun 2023 19:07:52 -0400 Subject: [PATCH] fix: properly handle failed bulk creates with no errors --- lib/ash/api/api.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/ash/api/api.ex b/lib/ash/api/api.ex index 0fdc2045..f821928e 100644 --- a/lib/ash/api/api.ex +++ b/lib/ash/api/api.ex @@ -1883,6 +1883,22 @@ defmodule Ash.Api do api |> bulk_create(inputs, resource, action, opts) |> case do + %Ash.BulkResult{status: :error, errors: []} -> + if opts[:return_errors?] do + raise Ash.Error.to_error_class( + Ash.Error.Unknown.UnknownError.exception( + error: "Something went wrong with bulk create, but no errors were produced." + ) + ) + else + raise Ash.Error.to_error_class( + Ash.Error.Unknown.UnknownError.exception( + error: + "Something went wrong with bulk create, but no errors were produced due to `return_errors?` being set to `false`." + ) + ) + end + %Ash.BulkResult{status: :error, errors: errors} -> raise Ash.Error.to_error_class(errors)