Skip to content

Commit c042d7d

Browse files
improvement: better error message on unexpected argument inputs to code interfaces (#2102)
1 parent f13094b commit c042d7d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/ash/code_interface.ex

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,27 @@ defmodule Ash.CodeInterface do
658658
arg_params = unquote(arg_params)
659659

660660
params =
661-
if is_list(params),
662-
do: Enum.map(params, &Map.merge(&1, arg_params)),
663-
else: Map.merge(params, arg_params)
661+
if is_list(params) do
662+
Enum.map(params, fn item ->
663+
if is_map(item) do
664+
Map.merge(item, arg_params)
665+
else
666+
raise ArgumentError, """
667+
Expected `params` to be a map or a list of maps.
668+
Got: #{inspect(params)}
669+
"""
670+
end
671+
end)
672+
else
673+
if is_map(params) do
674+
Map.merge(params, arg_params)
675+
else
676+
raise ArgumentError, """
677+
Expected `params` to be a map or a list of maps.
678+
Got: #{inspect(params)}
679+
"""
680+
end
681+
end
664682

665683
case Enum.filter(unquote(interface.exclude_inputs || []), fn input ->
666684
if is_list(params) do

0 commit comments

Comments
 (0)