RulesEngine icon indicating copy to clipboard operation
RulesEngine copied to clipboard

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

Open taskinozdemir opened this issue 1 year ago • 3 comments

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 avatar Mar 01 '24 07:03 taskinozdemir

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.

taskinozdemir avatar Mar 05 '24 08:03 taskinozdemir

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

asulwer avatar Jun 27 '24 21:06 asulwer

your PR has been merged with my fork, manually

asulwer avatar Jun 27 '24 22:06 asulwer