isPresent(givenName) ? '%s %s'.format(givenName, familyName) : str(familyName)
MidPoint Expression Language Troubleshooting
|
MidPoint Expression Language feature
This page describes configuration of MidPoint Expression Language midPoint feature.
Please see the feature page for more details.
|
Common Errors
Expression written in midPoint expression language (MEL) are interpreted by common expression language (CEL) interpreter. CEL is a foundational language on which MEL expressions are built. However, the CEL compiler and runtime which is used to evaluate MEL expressions is very technical in nature. While we have made a lot of convenience improvements and extensions while creating MEL, we could not fundamentally change the nature of underlying CEL engine.
The nature of CEL engine manifests itself mostly in cryptic and often confusing error messages. Below is a list mysterious of error messages that are likely to occur when constructing MEL expressions, together with explanation and tips on problem resolution.
Field selections must be performed on messages or maps.-
This error message probably indicates that a
nullvalue was used as a base for structured data resolution. E.g. for codeinput.orig, where variableinputisnull. The solution is to use.?operator for optional resolution, e.g.input.?orig. Found no matching overload for '?:_' applied to … (candidates: (bool, %A8, %A8))-
Conditional operator (
?:) must have the same data type in both branches. E.g. both branches must evaluate to string. This error is usually raised when one of the branches evaluates to string, while the other evaluates to polystring. While strings and polystrings are functionally equivalent in most cases, conditional operator is an exception. The solution is to explicitly convert the polystring branch to string usingstr()orstringify()function, e.g.:Even better solution would be to replace the conditional with
default()orformat.concatName()function. No matching overload for function '+'. Overload candidates: add_string-
This error indicates that the add operator (
`) was invoked with an unexpected operand. Most likely situation is that one of the operands is `null`. This error often happens when addition operator (`) is used for string concatenation of optional values, e.g.:'This is ' + input // This code is fragileThe expression above fails if the
inputvariable isnull, producing the error message above. The code can be made more robust by using theformat()function:'This is %s'.format(input) // Robust codeHowever, even such code may not be perfect, as the expression above would produce string
This is nullin case that theinputvariable isnull. This is usually not the desired output. The expression can further be improved by usingdefault()function:'This is %s'.format(default(input,'nothing')) // Correct codeSuch expression would produce string
This is nothingin case that theinputvariable isnull, which is probably more acceptable output.
Null Value Checks
Does your expression contain a check for null value which does not seem to work?
To cut a very long story short: Never use equality operator to check for null:
foo == null
Use isNull() or isPresent() function instead, and all will be fine.
isNull(foo)
These problems are caused by CEL engine using two different ways to represent value which is not present (null and emtpty optional). Detailed explanation of this phenomenon is provided in See Null and Optional Values section of MEL specification.
Common Problems
- My
"foo"string does not work -
Strings are delimited by apostrophes in MEL. Correct string literal is
'foo'. - Check for
isPresent(focus.fullName)fails. -
Of course it does. If focus does not have
fullNameproperty, then the codefocus.fullNamefails, and theisPresent()function is not executed. The correct form is using optional selection (.?) to avoid failing on missing property:isPresent(focus.?fullName). Alternatively, CELhas()macro could be used:has(focus.fullName). However, thehas()macro fails in case that thefocusvariable isnull. The use ofisPresent(focus.?fullName)is recommended. - Variable
useris not there! -
That is right. Variable
useris deprecated for many years, and it is not exposed to new expression environments such as MEL. Use variables such asfocusandprojectioninstead. - String formatting:
'%s %s'.format(foo, bar)does not work. -
CEL does not support functions with variable number of arguments (vararg). Therefore you have to use list literal (
[]) when passing multiple arguments to logging functions:'%s %s'.format([ foo, bar ]) - Logging:
log.error('{} - {}', foo, bar)does not work. -
CEL does not support functions with variable number of arguments (vararg). Therefore you have to use list literal (
[]) when passing multiple arguments to logging functions:log.error('{} - {}', [ foo, bar ])