Propose using $var
syntax if evaluation IF or WHILE condition using ${var}
fails
#4676
Milestone
$var
syntax if evaluation IF or WHILE condition using ${var}
fails
#4676
A common error when evaluating expressions with IF or otherwise is using something like
when the variable
${x}
contains a string. Normal variables are resolved before evaluating the expression, so if${x}
contains a stringvalue
, the evaluated expression will bevalue == 'expected'
. Evaluating it fails becausevalue
isn't quoted, it's thus considered a variable in Python, and no such variable exists. The resulting error is this:One solution to this problem is quoting the variable like
'${x}' == 'expected'
, but that doesn't work if the variable value contains quotes or newlines. A better solution is using the special$var
syntax like$x == 'value'
that makes the variable available in the Python evaluation namespace (#2040). All this is explained in the User Guide, but there are many users who don't know about this and struggle with the syntax.Because this is a such a common error, we should make the error more informative if the expression contains "normal" variables. We could, for example, show also the original expression and recommend quoting or using the "special" variable syntax. Possibly it could look like this:
There are few problems implementing this:
'${x}' == value
where the variable likely isn't a problem. We could try some heuristics to see what causes the error, but that's probably too much work compared to including the extra info in some cases where it's not needed.Because this extra info is added only if evaluation fails, this should be a totally backwards compatible change. It would be nice to include it already into RF 6.1, but that release is already about to be late and this isn't that easy to implement, so RF 6.2 is probably a better target. If someone is interested to look at this, including it already into RF 6.1 ought to be possible.
The text was updated successfully, but these errors were encountered: