Recursive action should generate compile warning and runtime error


A recursive action should generate compile warning and runtime error.

An action which calls itself can be valid code.  However, it is likely to be an error, which would result in downtime if called.

In TrueChange:

Suggest a warning should be displayed in TrueChange if a Logic action calls itself.  This is possibly an error, but also could be valid.

Suggest an error should be displayed in TrueChange if a Logic action calls itself without any other code.  This is definitely an error.

At runtime:

Suggest a maximum number of recursions should be a configurable platform item.  Or if not, it is set high enough not to cause issues with valid code, but low enough that an error may be generated before the stack generates an error.

When an action is recursed more than the maximum number of recursions an exception is thrown with the name of the action saying the action has exceeded the maximum number of recursions.

It would be great if this could handle cyclic calls involving multiple actions at runtime.  It would be amazing if that could be determined at compile time.

Created on 11 Jun (7 days ago)
Comments (3)

Changed the category to 1CP

Recursive actions are indeed valid code, and I use them occasionally, though I've also created them inadvertently, so I'm not sure whether I would like warnings.

I don't see any value to limit the number of recursions, from an end-user point of view there's little difference between a "max. number of recursions reached" exception or a "stack overflow" exception.

Hi Killian, Thanks for commenting and adding your insight.  I would totally agree about the stack overflow exception if it was logged or exposed.  I also agree about having false positive warnings for valid code.  I am a little conflicted about that, weighing up the possibility of bringing the site down versus a warning for a valid but rare piece of logic.

The issue we experienced is the platform does not appear to throw a stack overflow exception, or if it does, it is not displayed to the user or in the logs, so you are not aware it is happening.  We had a recursive call in a layout function and it brought the whole site down without giving and indication of what was wrong or where it is located.

The value is that when recursion gone wrong, it can cause a significant problem.  This idea would highlight the cause and the location for fast remediation.

Maybe if the site was able to expose the stack overflow exception, which would highlight the cause and location, the same benefit would be realised.  Although, I still think there is benefit in the compile time error where incorrect logic can be determined.

Your comment also helps me understand I should have added that explanation originally.  Many thanks!