Describe the bug
When using Ash.Type.NewType with an invalid value for the :fields argument in test_create action, an internal server error occurs instead of returning a JSON list of errors. Specifically, the error ** (CaseClauseError) no case clause matching: {:error, "is invalid"} is raised, indicating a failure in handling invalid field values within Ash.Type.Map.
To Reproduce
Steps to reproduce the behavior include:
Define a custom Ash type with Ash.Type.NewType, as shown in App.Type.TestMap.
Define an action test_create with an argument :fields of type {:array, App.Type.TestMap}.
Pass an invalid value for :fields, e.g., a number for a string attribute.
Here is the relevant code:
action :test_create, :struct do
# argument :fields, {:array, App.Resource.TestMap}, allow_nil?: false
# above works fine but below throws the error
argument :fields, {:array, App.Type.TestMap}, allow_nil?: false
run fn input, context ->
{:ok, nil}
end
end
defmodule App.Resource.TestMap do
use Ash.Resource,
data_layer: :embedded
attributes do
attribute :nullable, :string, allow_nil?: true, public?: true
end
end
defmodule App.Type.TestMap do
use Ash.Type.NewType,
subtype_of: :map,
constraints: [
fields: [
nullable: [type: :string, allow_nil?: true],
],
]
end
Expected behavior
Instead of raising an internal server error, the code should return a proper error (as seen with App.Resource.TestMap).
Describe the bug
When using
Ash.Type.NewType
with an invalid value for the:fields
argument intest_create
action, an internal server error occurs instead of returning a JSON list of errors. Specifically, the error** (CaseClauseError) no case clause matching: {:error, "is invalid"}
is raised, indicating a failure in handling invalid field values withinAsh.Type.Map
.To Reproduce
Steps to reproduce the behavior include:
Ash.Type.NewType
, as shown inApp.Type.TestMap
.test_create
with an argument:fields
of type{:array, App.Type.TestMap}
.:fields
, e.g., a number for a string attribute.Here is the relevant code:
Expected behavior
Instead of raising an internal server error, the code should return a proper error (as seen with
App.Resource.TestMap
).Error backtrace
Runtime