Drools rule condition error handling

316 views
Skip to first unread message

Ramya Loganathan

unread,
Jul 2, 2023, 12:52:05 AM7/2/23
to Drools Usage

Hi team,

Consider a drl rule definition below
Github drl file definition

We are trying to use dynamic data types like Map<String,Object>.

Scenario 1:

m : HashMap( this["age"] > 14 && this["clicks"] + this["visits"] > 500 )

For a rule with conditions like the above, the second part this["clicks"] + this["visits"] > 500 throws an exception if any of the parameters are missing in the HashMap. When an exception is thrown in any of the rules in a kie session, the whole kie session gets terminated without any further execution or rule outcome.

Scenario 2:
m : HashMap(  Double.parseDouble(this["visits"]) > 500 )

Here, if the visits param is null, then there will be an exception thrown from the rule and the whole kie session will be affected.

The way I want to handle this scenario is, any rule throwing the exception alone should fail and there must be a way to catch the exception and fail gracefully with additional logging. Other rules in the same kie session must continue the rule activation and execution without an abrupt halt.

If there is an exception listener like https://docs.drools.org/5.6.0.Final/knowledge-api-javadoc/index.html?org/drools/conf/ConsequenceExceptionHandlerOption.html
for the drools condition evaluation, it may be helpful.

Do we have any such feature? Or is there a way to achieve this expected behaviour via some drools configuration?

In case a sample project is required to test, please clone this simple app and try out the same.

Scenario one is available in  Drools sample app

Toshiya Kobayashi

unread,
Jul 4, 2023, 4:44:17 AM7/4/23
to Drools Usage
Hello,

There is no exception handler for conditions (LHS), so I think it's not possible to achieve "any rule throwing the exception alone should fail and there must be a way to catch the exception and fail gracefully with additional logging. Other rules in the same kie session must continue the rule activation and execution without an abrupt halt".

You need to validate the facts beforehand.

Regards,
Toshiya

2023年7月2日日曜日 13:52:05 UTC+9 lramya2...@gmail.com:

Gabriele Cardosi

unread,
Jul 4, 2023, 5:31:57 AM7/4/23
to drools...@googlegroups.com
Hello,
the following ticket has been created and under evaluation:
https://github.com/kiegroup/kie-issues/issues/379

Thanks for reporting this.

Best regards,

Gabriele

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/bb8c66c7-5675-4d1c-b97b-3c867cb72a2an%40googlegroups.com.


--

GABRIELE CARDOSI

SENIOR SOFTWARE ENGINEERS, MW

Red Hat Ltd

gcar...@redhat.com    M: +39-3461717132    

Gabriele Cardosi

unread,
Jul 4, 2023, 5:32:17 AM7/4/23
to drools...@googlegroups.com
Hello,
the following ticket has been created and under evaluation:
https://github.com/kiegroup/kie-issues/issues/379

Thanks for reporting this.

Best regards,

Gabriele

On Tue, Jul 4, 2023 at 10:44 AM Toshiya Kobayashi <toshiyak...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/bb8c66c7-5675-4d1c-b97b-3c867cb72a2an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages