Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.16] fix: Unary-test behavior with special input variable ? #906

Merged
merged 11 commits into from
Aug 27, 2024
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@
<className>org/camunda/feel/syntaxtree/Range</className>
<differenceType>8001</differenceType>
</ignored>
<!-- ignore auto-generated Scala functions -->
<ignored>
<className>org/camunda/feel/syntaxtree/**</className>
<differenceType>7002</differenceType>
<method>scala.Function1 andThen(scala.Function1)</method>
</ignored>
<ignored>
<className>org/camunda/feel/syntaxtree/**</className>
<differenceType>7002</differenceType>
<method>scala.Function1 compose(scala.Function1)</method>
</ignored>
</ignored>
</configuration>
</plugin>
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/org/camunda/feel/FeelEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.camunda.feel.FeelEngine.{
import org.camunda.feel.context.{Context, FunctionProvider, VariableProvider}
import org.camunda.feel.impl.interpreter.{BuiltinFunctions, EvalContext, FeelInterpreter}
import org.camunda.feel.impl.parser.{ExpressionValidator, FeelParser}
import org.camunda.feel.syntaxtree.{Exp, ParsedExpression, ValError}
import org.camunda.feel.syntaxtree.{Exp, ParsedExpression, ValError, ValFatalError}
import org.camunda.feel.valuemapper.ValueMapper.CompositeValueMapper
import org.camunda.feel.valuemapper.{CustomValueMapper, ValueMapper}

Expand Down Expand Up @@ -205,9 +205,11 @@ class FeelEngine(

private def eval(exp: ParsedExpression, context: EvalContext): EvalExpressionResult = {
interpreter.eval(exp.expression)(context) match {
case ValError(cause) =>
case ValError(cause) =>
Left(Failure(s"failed to evaluate expression '${exp.text}': $cause"))
case value => Right(valueMapper.unpackVal(value))
case ValFatalError(cause) =>
Left(Failure(s"failed to evaluate expression '${exp.text}': $cause"))
case value => Right(valueMapper.unpackVal(value))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.camunda.feel.syntaxtree.{
ValDateTime,
ValDayTimeDuration,
ValError,
ValFatalError,
ValFunction,
ValList,
ValLocalDateTime,
Expand Down Expand Up @@ -170,8 +171,9 @@ class DefaultValueMapper extends CustomValueMapper {
}.toMap
)

case f: ValFunction => Some(f)
case e: ValError => Some(e)
case f: ValFunction => Some(f)
case e: ValError => Some(e)
case fatalError: ValFatalError => Some(fatalError)

case _ => None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.camunda.feel.impl.builtin

import org.camunda.feel.logger
import org.camunda.feel.syntaxtree.{Val, ValError, ValFunction, ValNull}
import org.camunda.feel.syntaxtree.{Val, ValError, ValFatalError, ValFunction, ValNull}

object BuiltinFunction {

Expand All @@ -34,12 +34,13 @@ object BuiltinFunction {
}

private def error: PartialFunction[List[Val], Any] = {
case vars if (vars.exists(_.isInstanceOf[ValError])) =>
vars.filter(_.isInstanceOf[ValError]).head.asInstanceOf[ValError]
case e => {
logger.warn(s"Suppressed failure: illegal arguments: $e")
case args if args.exists(_.isInstanceOf[ValFatalError]) =>
args.find(_.isInstanceOf[ValFatalError])
case args if args.exists(_.isInstanceOf[ValError]) => args.find(_.isInstanceOf[ValError])
case args =>
val argumentList = args.map("'" + _ + "'").mkString(", ")
logger.warn(s"Suppressed failure: Illegal arguments: $argumentList")
ValNull
}
}

}
Loading
Loading