EnableExceptionAsErrorMessage = false does not actually throw exception, but ignores/supresses it
STR
Have any invalid rule or one that somehow else throws an exception.
And have the settings configured as such:
var engineSettings = new ReSettings()
{
CustomActions = // ...
CustomTypes = // ...
EnableExceptionAsErrorMessage = false
};
new RulesEngine.RulesEngine(mailWorkflows, engineSettings);
What should happen
EnableExceptionAsErrorMessage = false is explained on https://microsoft.github.io/RulesEngine/#settings should do the following:
Otherwise [= if false], throws an exception. This setting is only applicable if IgnoreException is set to false.
Notably IgnoreException is not touched, i.e. it is (as per https://microsoft.github.io/RulesEngine/#settings aka the default set to false)
What happens
Errors are silently ignored.
More information
I have also indicated this in https://github.com/microsoft/RulesEngine/issues/623, see this for a practical example.
System
<TargetFramework>net8.0</TargetFramework>
<!-- ... -->
<PackageReference Include="RulesEngine" Version="5.0.3" />
aka .NET 8
Windows 10
Okay tried it with a simple ruie with wrong Success name, ...
"OnSuccess": {
"Name": "EvaluateRuleX",
"Context": {
}
},
and when debugging (catching all CLR exceptions), I e.g. land here: https://github.com/microsoft/RulesEngine/blob/dc5298989583954cd6aac598267747b4ce635f45/src/RulesEngine/Actions/ActionBase.cs#L22
It handles the exception and returns it.
At least for such "system exceptions". it's quite obvious there that these are ignored?
I also reproduced this in your DemoApp -this time using an obvious syntax error in an expression that results in an
index 88f9ad9..54e5c95 100644
--- a/demo/DemoApp/JSONDemo.cs
+++ b/demo/DemoApp/JSONDemo.cs
@@ -41,7 +41,10 @@ namespace DemoApp
var fileData = File.ReadAllText(files[0]);
var workflow = JsonConvert.DeserializeObject<List<Workflow>>(fileData);
- var bre = new RulesEngine.RulesEngine(workflow.ToArray(), null);
+ var bre = new RulesEngine.RulesEngine(workflow.ToArray(), new ReSettings() {
+ EnableExceptionAsErrorMessage = false,
+ IgnoreException = false
+ });
string discountOffered = "No discount offered.";
diff --git a/demo/DemoApp/Workflows/Discount.json b/demo/DemoApp/Workflows/Discount.json
index ad556d9..eb3b156 100644
--- a/demo/DemoApp/Workflows/Discount.json
+++ b/demo/DemoApp/Workflows/Discount.json
@@ -8,7 +8,7 @@
"ErrorMessage": "One or more adjust rules failed.",
"ErrorType": "Error",
"RuleExpressionType": "LambdaExpression",
- "Expression": "input1.country == \"india\" AND input1.loyaltyFactor <= 2 AND input1.totalPurchasesToDate >= 5000 AND input2.totalOrders > 2 AND input3.noOfVisitsPerMonth > 2"
+ "Expression": "input1.countr == \"india\" AND input1.loyaltyFactor <= 2 AND input1.totalPurchasesToDate >= 5000 AND input2.totalOrders > 2 AND input3.noOfVisitsPerMonth > 2"
},
{
"RuleName": "GiveDiscount20",
Ah okay, if I change it to input1X.countr this correctly throws though:
Unhandled exception. RulesEngine.Exceptions.RuleException: Error while compiling rule
GiveDiscount10: Unknown identifier 'input1X' ---> Unknown identifier 'input1X' (at index 0)
Maybe it only affects ActionWorkflows though, where you have no example for in the demo apps as far as I see?
Also asked a related question about this, because it totally confuses me how many places there are to store some exceptions (or exception messages): https://github.com/microsoft/RulesEngine/discussions/628