Skip to content
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

EnableExceptionAsErrorMessage = false does not actually throw exception, but ignores/supresses it #624

Open
rklec opened this issue Aug 12, 2024 · 3 comments

Comments

@rklec
Copy link

rklec commented Aug 12, 2024

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 #623, see this for a practical example.

System

    <TargetFramework>net8.0</TargetFramework>
<!-- ... -->
    <PackageReference Include="RulesEngine" Version="5.0.3" /> 

aka .NET 8

Windows 10

@rklec
Copy link
Author

rklec commented Aug 12, 2024

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:

result.Exception = new Exception($"Exception while executing {GetType().Name}: {ex.Message}", ex);

It handles the exception and returns it.

At least for such "system exceptions". it's quite obvious there that these are ignored?

@rklec
Copy link
Author

rklec commented Aug 12, 2024

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?

@rklec
Copy link
Author

rklec commented Aug 29, 2024

Also asked a related question about this, because it totally confuses me how many places there are to store some exceptions (or exception messages): #628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant