Safe Evaluation Mode #630
salvalcantara
started this conversation in
Ideas
Replies: 1 comment
-
Instead of replacing unresolvable attributes with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Examples
For the following JSON payload:
I want these expressions to evaluate to
false
, for example:As of now, all will fail due to missing fields. An obvious solution is to make the expressions safe beforehand like this:
But that's precisely what I want to avoid.
Proposed Solution: Safe Evaluation Mode
The main idea would be to replace unresolvable attributes with
null
.For
a.b == 1
that would give usnull == 1
which would evaluate tofalse
as desired.The problem is when you have something more like this
a.b > 1
because that would be transformed intonull > 1
and then evaluation would fail with ano such overload
error due to the null type not supporting the>
operator. The same might happen for other operators/functions. To account for this, the interpreter could consider an evaluation type of middleware which simply inspects if there are any (non-)errors like those due to missing fields and if that's the case simply returnfalse
.Rough Sketch
Optionally, decorate the interpreter like this:
where:
SafeEvalAttr
would do the replacement withnull
for nonresolvable attributesSafeEval
would act as a middleware to ignore the (non-)errors caused bySafeEvalAttr
(and potentially others)The former would be a trivial tweak of EvalAttr, while the latter would look like this:
This safe evaluation mode would be disabled by default, but could be optionally enabled by the user.
Beta Was this translation helpful? Give feedback.
All reactions