fix: raise better error on invalid filter values

closes #154

We still want to build something better directly into `Ash.Filter`
that determines field types and casts them up front
This commit is contained in:
Zach Daniel 2023-06-28 11:29:54 -04:00
parent ce9ca1ced2
commit a09dae4d26
2 changed files with 19 additions and 0 deletions

View file

@ -1313,6 +1313,15 @@ defmodule AshPostgres.DataLayer do
end
end
defp handle_raised_error(%Ecto.Query.CastError{} = e, stacktrace, context, resource) do
handle_raised_error(
Ash.Error.Query.InvalidFilterValue.exception(value: e.value, context: context),
stacktrace,
context,
resource
)
end
defp handle_raised_error(error, stacktrace, _context, _resource) do
{:error, Ash.Error.to_ash_error(error, stacktrace)}
end

View file

@ -18,6 +18,16 @@ defmodule AshPostgres.FilterTest do
end
end
describe "invalid uuid" do
test "with an invalid uuid, an invalid error is raised" do
assert_raise Ash.Error.Invalid, fn ->
Post
|> Ash.Query.filter(id == "foo")
|> Api.read!()
end
end
end
describe "citext validation" do
setup do
on_exit(fn ->