fix: properly catch errors when running expressions at runtime

This commit is contained in:
Zach Daniel 2022-09-14 19:50:07 -04:00
parent a572099e24
commit 3baf2b8c97
3 changed files with 18 additions and 9 deletions

View file

@ -100,15 +100,20 @@ defmodule Ash.Filter.Runtime do
|> Enum.reject(&Ash.Resource.loaded?(record, &1))
|> case do
[] ->
{:ok,
record
|> flatten_relationships(relationship_paths)
|> Enum.any?(fn scenario ->
case do_match(scenario, expression) do
{:ok, val} -> val
_ -> false
end
end)}
record
|> flatten_relationships(relationship_paths)
|> Enum.reduce_while({:ok, false}, fn scenario, {:ok, false} ->
case do_match(scenario, expression) do
{:error, error} ->
{:halt, {:error, error}}
{:ok, val} when val ->
{:halt, {:ok, true}}
{:ok, _} ->
{:cont, {:ok, false}}
end
end)
need_to_load ->
{:load, Enum.map(need_to_load, &path_to_load/1)}

View file

@ -54,6 +54,9 @@ defmodule Ash.Query.Function do
:unknown ->
{:ok, function}
{:error, error} ->
{:error, error}
end
end

View file

@ -59,6 +59,7 @@ defmodule Ash.Query.Operator do
{:ok, val} when not is_expr(left) and not is_expr(right) ->
case mod.evaluate(val) do
{:known, value} -> {:ok, value}
{:error, error} -> {:error, error}
:unknown -> {:ok, val}
end