You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Problems with recommentation to use $var syntax if expression evaluation fails #5274
A common error when evaluating expressions with IF or otherwise is using something like
IF ${x} == 'expected'
Keyword
END
The resulting error message was enhanced in RF 6.1 (#4676) to recommend using the $x syntax, and what you get nowadays is something like this:
Invalid IF condition: Evaluating expression "xxx == 'expected'" failed: NameError: name 'xxx' is not defined nor importable as module
Variables in the original expression "${x} == 'expected'" were resolved before the expression was evaluated. Try using "$x == 'expected'" syntax to avoid that. See Evaluating Expressions appendix in Robot Framework User Guide for more details.
This works fine otherwise, but if the variable has been quoted and evaluation fails because the variable contains a matching quote or a newline. For example, if ${x} contains x'x and you use
IF '${x}' == 'expected'
Keyword
END
the recommendation part of the error is this:
Try using "'$x' == 'expected'" syntax to avoid that.
The above recommendation isn't correct, because '$x' would be treated as a literal string where $x has no special meaning. The correct recommendation would be this one without quotes around $x:
Try using "$x == 'expected'" syntax to avoid that.
Although this is only a recommendation in an error situation, the recommendation being wrong is somewhat severe. Luckily it is pretty easy to detect is the original variable quoted and remove quotes in that case.
changed the title [-]Recommentation to use `$var` syntax should remove possible quoting from example[/-][+]Problems with recommentation to use `$var` syntax if expression evaluation fails[/+]on Nov 21, 2024
When creating tests for this problem, I notice that the are problem also if the expression contains more than one variable. For example, using an expression ${x} or ${y} when these variables contain strings gives us this invalid recommendation:
Try using '$x or ${y} or $y' syntax to avoid that.
Activity
[-]Recommentation to use `$var` syntax should remove possible quoting from example[/-][+]Problems with recommentation to use `$var` syntax if expression evaluation fails[/+]pekkaklarck commentedon Nov 21, 2024
When creating tests for this problem, I notice that the are problem also if the expression contains more than one variable. For example, using an expression
${x} or ${y}when these variables contain strings gives us this invalid recommendation:I'll fix that at the same time.
pekkaklarck commentedon Nov 21, 2024
The latter problem was due to the code using
when it was supposed to be
Took some time to see the difference. This example demonstrates how it affected results:
Fixes to $var recommendation.