-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
no_matching_bulk_strategy.ex
57 lines (49 loc) · 1.45 KB
/
no_matching_bulk_strategy.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
defmodule Ash.Error.Invalid.NoMatchingBulkStrategy do
@moduledoc "Used when an identity name is used that does not reference identity on the resource"
use Ash.Error.Exception
use Splode.Error,
fields: [
:resource,
:action,
:requested_strategies,
:not_stream_reason,
:not_atomic_batches_reason,
:not_atomic_reason,
:footer
],
class: :invalid
def message(%{
resource: resource,
action: action,
footer: footer,
not_stream_reason: not_stream_reason,
requested_strategies: requested_strategies,
not_atomic_batches_reason: not_atomic_batches_reason,
not_atomic_reason: not_atomic_reason
}) do
action =
if is_atom(action) do
action
else
action && action.name
end
reasons =
[
"Could not use `:stream`": not_stream_reason || "Not in requested strategies",
"Could not use `:atomic_batches`":
not_atomic_batches_reason || "Not in requested strategies",
"Could not use `:atomic`": not_atomic_reason || "Not in requested strategies"
]
|> Enum.map_join("\n", fn {reason, message} -> "#{reason}: #{message}" end)
footer =
if footer do
"\n\n#{footer}"
end
"""
#{inspect(resource)}.#{action} had no matching bulk strategy that could be used.
Requested strategies: #{inspect(requested_strategies)}
#{reasons}
#{footer}
"""
end
end