Skip to content

Commit 9dee17a

Browse files
committed
Fixes #15 AggregateException that contained more than one inner exception would be discarded.
1 parent 48d7cd5 commit 9dee17a

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

Source/Shared/Exceptionless.Portable.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Plugins\Default\040_ReferenceIdPlugin.cs" />
7272
<Compile Include="Plugins\Default\020_SimpleErrorPlugin.cs" />
7373
<Compile Include="Plugins\Default\050_EnvironmentInfoPlugin.cs" />
74+
<Compile Include="Plugins\Default\015_HandleAggregateExceptionsPlugin.cs" />
7475
<Compile Include="Plugins\PriortyAttribute.cs" />
7576
<Compile Include="EventBuilder.cs" />
7677
<Compile Include="Events\ConfigurationUpdatedEventArgs.cs" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using Exceptionless.Dependency;
3+
using Exceptionless.Models;
4+
5+
namespace Exceptionless.Plugins {
6+
[Priority(15)]
7+
public class HandleAggregateExceptionsPlugin : IEventPlugin {
8+
public void Run(EventPluginContext context) {
9+
var aggregateException = context.ContextData.GetException() as AggregateException;
10+
if (aggregateException == null)
11+
return;
12+
13+
var exception = aggregateException.Flatten();
14+
if (exception.InnerExceptions.Count == 1) {
15+
context.ContextData.SetException(exception.InnerException);
16+
return;
17+
}
18+
19+
foreach (var ex in exception.InnerExceptions) {
20+
var ctx = new ContextData(context.ContextData);
21+
ctx.SetException(ex);
22+
23+
var serializer = context.Resolver.GetJsonSerializer();
24+
context.Client.SubmitEvent(serializer.Deserialize(serializer.Serialize(context.Event), typeof(Event)) as Event, ctx);
25+
}
26+
27+
context.Cancel = true;
28+
}
29+
}
30+
}

Source/Shared/Plugins/EventPluginManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static void Run(EventPluginContext context) {
2525

2626
public static void AddDefaultPlugins(ExceptionlessConfiguration config) {
2727
config.AddPlugin<ConfigurationDefaultsPlugin>();
28+
config.AddPlugin<HandleAggregateExceptionsPlugin>();
2829
config.AddPlugin<SimpleErrorPlugin>();
2930
config.AddPlugin<DuplicateCheckerPlugin>();
3031
config.AddPlugin<EnvironmentInfoPlugin>();

Source/Tests/Plugins/PluginTests.cs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Exceptionless.Plugins.Default;
99
using Exceptionless.Models;
1010
using Exceptionless.Models.Data;
11+
using Exceptionless.Submission;
1112
using Exceptionless.Tests.Utility;
1213
using Xunit;
1314
using Xunit.Abstractions;
@@ -41,7 +42,7 @@ public void ConfigurationDefaults_EnsureNoDuplicateTagsOrData() {
4142
}
4243
}
4344

44-
[Fact]
45+
[Fact]
4546
public void ConfigurationDefaults_IgnoredProperties() {
4647
var client = new ExceptionlessClient();
4748
client.Configuration.DefaultData.Add("Message", "Test");
@@ -58,6 +59,73 @@ public void ConfigurationDefaults_IgnoredProperties() {
5859
Assert.Equal(1, context.Event.Data.Count);
5960
Assert.Equal("Test", context.Event.Data["Message"]);
6061
}
62+
63+
[Fact]
64+
public void IgnoreUserAgentPlugin_DiscardBot() {
65+
var client = new ExceptionlessClient();
66+
client.Configuration.AddUserAgentBotPatterns("*Bot*");
67+
var plugin = new IgnoreUserAgentPlugin();
68+
69+
var ev = new Event();
70+
var context = new EventPluginContext(client, ev);
71+
plugin.Run(context);
72+
Assert.False(context.Cancel);
73+
74+
ev.AddRequestInfo(new RequestInfo { UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4" });
75+
context = new EventPluginContext(client, ev);
76+
plugin.Run(context);
77+
Assert.False(context.Cancel);
78+
79+
ev.AddRequestInfo(new RequestInfo { UserAgent = "Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)" });
80+
context = new EventPluginContext(client, ev);
81+
plugin.Run(context);
82+
Assert.True(context.Cancel);
83+
}
84+
85+
[Fact]
86+
public void HandleAggregateExceptionsPlugin_SingleInnerException() {
87+
var client = new ExceptionlessClient();
88+
var plugin = new HandleAggregateExceptionsPlugin();
89+
90+
var exceptionOne = new Exception("one");
91+
var exceptionTwo = new Exception("two");
92+
93+
var context = new EventPluginContext(client, new Event());
94+
context.ContextData.SetException(exceptionOne);
95+
plugin.Run(context);
96+
Assert.False(context.Cancel);
97+
98+
context = new EventPluginContext(client, new Event());
99+
context.ContextData.SetException(new AggregateException(exceptionOne));
100+
plugin.Run(context);
101+
Assert.False(context.Cancel);
102+
Assert.Equal(exceptionOne, context.ContextData.GetException());
103+
104+
context = new EventPluginContext(client, new Event());
105+
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
106+
plugin.Run(context);
107+
Assert.False(context.Cancel);
108+
Assert.Equal(exceptionOne, context.ContextData.GetException());
109+
}
110+
111+
[Fact]
112+
public void HandleAggregateExceptionsPlugin_MultipleInnerException() {
113+
var submissionClient = new InMemorySubmissionClient();
114+
var client = new ExceptionlessClient("LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw");
115+
client.Configuration.Resolver.Register<ISubmissionClient>(submissionClient);
116+
117+
var plugin = new HandleAggregateExceptionsPlugin();
118+
var exceptionOne = new Exception("one");
119+
var exceptionTwo = new Exception("two");
120+
121+
var context = new EventPluginContext(client, new Event());
122+
context.ContextData.SetException(new AggregateException(exceptionOne, exceptionTwo));
123+
plugin.Run(context);
124+
Assert.True(context.Cancel);
125+
126+
client.ProcessQueue();
127+
Assert.Equal(2, submissionClient.Events.Count);
128+
}
61129

62130
[Fact]
63131
public void ErrorPlugin_DiscardDuplicates() {
@@ -143,7 +211,7 @@ public void ErrorPlugin_CanProcessDifferentExceptionDataDictionaryTypes(IDiction
143211
Assert.Equal(processedDataItemCount, error.Data.Count);
144212
}
145213
}
146-
214+
147215
[Fact]
148216
public void ErrorPlugin_CopyExceptionDataToRootErrorData() {
149217
var errorPlugins = new List<IEventPlugin> {

0 commit comments

Comments
 (0)