Skip to content

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

Closed

Description

@rklec

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

Activity

  1. rklec commented on Aug 12, 2024

    @rklec
    Author

    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?

  2. rklec commented on Aug 12, 2024

    @rklec
    Author

    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?

  3. rklec commented on Aug 29, 2024

    @rklec
    Author

    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

  4. added a commit that references this issue on May 27, 2026
    29913a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions