microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.47k stars 528 forks source link

If an execution took an exception in the next runs error message is transfered even if it successes. #590

Open taskinozdemir opened 4 months ago

taskinozdemir commented 4 months ago

If a workflow took an exception in . In the next run error message is transfered even if It successes. Sample code is stated below.

public class HasException
{
    internal class TestClass
    {
        private int counter = 0;
        private string simpleProp;

        public string SimpleProp {
            get {
                if (counter++ == 0)
                {
                    throw new ArgumentException("Canım istedi");
                }
                return simpleProp;
            }
            set {
                simpleProp = value;
            }
        }
    }

    public void Run()
    {
        Console.WriteLine($"Running {nameof(NestedInputDemo)}....");

        TestClass instance = new();
        instance.SimpleProp = "simpleProp";

        Workflow workflow = new();
        workflow.WorkflowName = "NestedInputDemoWorkflow1";
        workflow.Rules = new List<Rule>() {
            new Rule() {
                RuleName = "CheckNestedSimpleProp",
                RuleExpressionType = RuleExpressionType.LambdaExpression,
                Expression = "SimpleProp == \"simpleProp\"",
                ErrorMessage = "One or more adjust rules failed."
            }
        };

        var settings = new ReSettings();
        settings.UseFastExpressionCompiler = false;
        var bre = new RulesEngine.RulesEngine(new Workflow[] { workflow }, settings);
        var resultList = bre.ExecuteAllRulesAsync(workflow.WorkflowName, instance).Result;
        resultList.OnSuccess((eventName) => {
            Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in success - {eventName}. {resultList[0].ExceptionMessage}");
        }).OnFail(() => {
            Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in failure. {resultList[0].ExceptionMessage}");
        });
        resultList = bre.ExecuteAllRulesAsync(workflow.WorkflowName, instance).Result;
        resultList.OnSuccess((eventName) => {
            Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in success - {eventName}");
        }).OnFail(() => {
            Console.WriteLine($"{workflow.WorkflowName} evaluation resulted in failure");
        });
    }
}
taskinozdemir commented 3 months ago

I have created a pr for fixing this issue https://github.com/microsoft/RulesEngine/pull/592. Also I added a unit test to simulate the problem. Can you help us. This is a critical issue.

asulwer commented 5 days ago

this project is no longer maintained but...my fork is. i will look into your code and merge into my fork

asulwer commented 5 days ago

your PR has been merged with my fork, manually