mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: properly catch errors when running expressions at runtime
This commit is contained in:
parent
a572099e24
commit
3baf2b8c97
3 changed files with 18 additions and 9 deletions
|
@ -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)}
|
||||
|
|
|
@ -54,6 +54,9 @@ defmodule Ash.Query.Function do
|
|||
|
||||
:unknown ->
|
||||
{:ok, function}
|
||||
|
||||
{:error, error} ->
|
||||
{:error, error}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue