Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a rule that calls GitHub api (using github_api module) to create branches and fetch code diffs.
This is a required step in my workflow so if, for any reason, I can't "talk" with GitHub I would like to abort the other actions that my rule fires and display an error message to the user.
I've been searching for a while but haven't found a way to stop the regular flow of the rules. Is it even possible to do that?
If it is possible, how can I do it?
Comment | File | Size | Author |
---|---|---|---|
#7 | rules-2288427-abort-rules-on-exception-with-tests.patch | 4.42 KB | jribeiro |
Comments
Comment #1
natanmoraesAfter searching and debugging Rules's code, I couldn't find a way to stop my rule from executing when an error occurs.
What do you think about adding a "RulesFatalException" exception? If that exception is thrown rules would abort the executing of the rule. I am looking at implementing this in the coming weeks.
Comment #2
natanmoraesI've updated the module so whenever a rules action callback function throws RulesFatalException, the Rules module will display an error on Rules' log and on Watchdog and will stop any further action from being executed.
Comment #3
gabrielmachadosantos CreditAttribution: gabrielmachadosantos commented+1 RTBC
Comment #4
jribeiro CreditAttribution: jribeiro commented+1 RTBC
Comment #5
skwashd CreditAttribution: skwashd commentedBased on twitter exchange with @dasjo, this needs test coverage. Updating accordingly.
Comment #6
jribeiro CreditAttribution: jribeiro commentedI will work on this tests, so I'm assigning the ticket for me.
Comment #7
jribeiro CreditAttribution: jribeiro commentedNew Patch containing the previous changes plus tests.
Thanks @natanmoraes.
Comment #8
skwashd CreditAttribution: skwashd commentedLooks good to me.
Comment #9
skwashd CreditAttribution: skwashd commentedComment #11
dixon_Giving the patch another go with the bot, since it was 2 months since it was green...
Comment #12
dixon_Patch still seems to apply and the patch is also green. +1 RTBC :)
Comment #13
fagoThanks folks, I like the feature. But with the current evaluation it will continue execution if used e.g. inside a loop. Imo it would make most sense to always abort at configuration / component level would make most sense. By exposing an action to throw an exception, you could even do so conditionally from a rule set also.
We should extend test coverage a bit also, such that we ensure it works properly with nested configurations like loops.
Aborting does not seem to be "fatal", so why not call the eception the same - RulesAbortEvaluationException or so ?
aborts
public
Comment #14
jribeiro CreditAttribution: jribeiro commentedComment #15
jribeiro CreditAttribution: jribeiro commentedWhen occurs the exception inside a loop, the loop breaks and the consecutive actions outside of the loop are executed.
We need to define the best approach when get the exception:
Case 1: Break only the current loop interaction, executing the next loop interaction and the consecutive actions outside of the loop.
Case 2: Break the entire loop and execute the consecutive actions outside of the loop.
Case 3: Abort the rule when get the first exception.
@fago can you explain better your idea about it?
Thanks
Comment #16
dasjomy understanding is that fago's idea stated in #13 is case 3: aborting the entire rule component being executed
Comment #17
johnorourke CreditAttribution: johnorourke commentedSubscribing