NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
859 stars 170 forks source link

Handler is not being called for InnerException #164

Closed i4rilu closed 5 years ago

i4rilu commented 5 years ago

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);
        }
    }
NickCraver commented 5 years ago

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 :)

i4rilu commented 5 years ago

It looks like the logic is already there. It just it's not working: https://github.com/NickCraver/StackExchange.Exceptional/blob/c36d68a86875c1ff79516bce5877aca073566a98/src/StackExchange.Exceptional.Shared/Error.cs#L91-L96

NickCraver commented 5 years ago

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