camunda / feel-scala

FEEL parser and interpreter written in Scala
https://camunda.github.io/feel-scala/
Apache License 2.0
120 stars 50 forks source link

Handle non-existing variables and context entries gracefully #674

Closed saig0 closed 1 year ago

saig0 commented 1 year ago

Describe the bug If I access a non-existing variable then the expression fails. To avoid failure, I must do a null check first.

x
// failed to evaluate expression 'x': no variable found for name 'x'

The behavior is the same for path expressions. If I access a non-existing context entry, the expression fails.

{a: 1}.b
// failed to evaluate expression '{a: 1}.b': context contains no entry with key 'b'

Related to https://github.com/camunda/feel-scala/issues/540. Related to https://github.com/camunda/feel-scala/issues/582.

To Reproduce Steps to reproduce the behavior:

  1. Evaluate the expression x
  2. Verify that the expression fails to evaluate

Expected behavior The expression should return null if a variable or a context entry doesn't exist.

x = null

{a: 1}.b = null

{a: 1}.b.c = null

null.b = null

If the path expression is applied to a filter and a context doesn't contain the entry, the resulting list should contain null for this item.

// non-member path filtering
[ { x: 1 }, { y: 2 } ].y = [ null, 2 ]

[ { x: 1 } ].y = [ null ]

The expected behavior is aligned with the DMN spec. It is verified by the TCK test cases:

Environment

korthout commented 1 year ago

ZPA triage: