NickCraver/StackExchange.Exceptional

Handler is not being called for InnerException

Closed this issue · 3 comments

Unit test to reproduce:

    [TestClass]
    public class ExceptionalTest
    {
        [TestInitialize]
        public void TestInitialize()
        {
            Exceptional.Configure(settings =>
            {
                settings.ExceptionActions.Clear();
                settings.ExceptionActions.AddHandler<ArgumentNullException>((e, ex) =>
                {
                    e.AddCommand(
                        new Command("Test", "Test")
                            .AddData("ParamName", ex.ParamName));
                });
                settings.DefaultStore = new MemoryErrorStore(100);
            });
        }

        [TestMethod]
        public void TestException()
        {
            var exception = new ArgumentNullException("param1");

            var error = exception.LogNoContext();

            Assert.IsNotNull(error.Commands);
            Assert.AreEqual(1, error.Commands.Count);
        }

        [TestMethod]
        public void TestInnerException()
        {
            var exception = new Exception("Test", new ArgumentNullException("param1"));

            var error = exception.LogNoContext();

            // Both are failling
            Assert.IsNotNull(error.Commands);
            Assert.AreEqual(1, error.Commands.Count);
        }
    }

The current behavior is intentional...but I'm trying to think of a downside of doing so. We could overwrite things from the parent is the main one. I think it may be a net win though - I'll try and poke a bit tonight :)

It looks like the logic is already there. It just it's not working:

var exCursor = e;
while (exCursor != null)
{
AddData(exCursor);
exCursor = exCursor.InnerException;
}

Oh hey, I fixed this in 4f211db - after testing in Stack Overflow next week I'll push a new package up, but it's available on MyGet already as 2.0.7 or higher: https://www.myget.org/feed/Packages/exceptional