-
Notifications
You must be signed in to change notification settings - Fork 2.4k
WHILE
loop
#4084
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
Comments
Also enhance error reporting with IF/ELSE with invalid condition and add more tests for handling WHILE afte failures.
WHILE loops (#4084) having condition already initially False will get NOT RUN status. This was how WHILE worked earlier, but it was changed recently when fixing problems with invalid conditions. FOR loops that have nothing to iterate over will also get NOT RUN status. In addition to that, their body is run once, with NOT RUN status, to show what would have been executed. This fixes #4184.
This is now mostly ready. Remaining things to do are:
|
|
A problem with WHILE loops is that it is very easy to create a loop that never terminates. There could be a bug in the condition itself or code that should be updating a variable used in the condition could have problems. This is pretty severe problem, because the only way to stop such a rampant loop is stopping the whole execution forcefully. That means that that output.xml is broken and log.html cannot be created. To ease avoiding infinite loops, we decided to allow limiting how many times or how long time a WHILE loop is executed. The idea is that if the limit is searched, the loop is not executed anymore and execution fails. The limit would be specified using an optional second argument
To avoid infinite loops by default, it probably would be a good idea to have a default limit. That limit needed to be high enough to not affect normal valid usages but small enough to actually break the loop at some point. Probably something like 100 times would be good. It should be possible to disable the limit with Because execution would fail if the limit is reaches, this functionality couldn't be used for executing some keywords a certain number of times. That isn't a big loss because FOR IN RANGE loops can be used instead in such situations. |
Implementing the limit functionality shouldn't be too complicated and we can do it still before RF 5.0. There aren't much open design decisions either. Only things I can think of are:
|
On Slack not everyone was happy about the addition as there are use cases, especially when doing RPA, to have very long or even infinite loops. Endless loop requiring the execution to be forcefully stopped and leaving a broken output.xml and no log or report was nevertheless considered so bad that the limit functionality was added. Based on the feedback the default limit was raised to 10000 iterations, though. It was also decided that just using a number like |
Makes it easier to configure it externally if needed. Part of #4084.
The above commit made the default limit a module level constant. It's now fairly easy to configure it if needed: from robot import run_cli
from robot.running import bodyrunner
bodyrunner.DEFAULT_WHILE_LIMIT = 10_000_000_000_000_000
run_cli() This isn't ideal because you cannot simply disable the limit and because |
We've had FOR loops for a long time and having WHILE loops would be handy as well. The most important use case would probably be implementing custom polling solutions. That would be more flexible and powerful syntax than what can be currently done with
Wait Until Keyword Succeeds
. The syntax would be something like this:Naturally you should be able to nest WHILE loops with other control structures. For example, IF in combination with planned BREAK and CONTINUE (#4079) would often be useful.
The text was updated successfully, but these errors were encountered: