Skip to content

Commit 45d9e2f

Browse files
authored
Merge pull request #114 from exceptionless/bug/exclusions
Wpf Error handler fixes and Null Reference checks
2 parents e406ef8 + 0936a12 commit 45d9e2f

24 files changed

+267
-37
lines changed

Exceptionless.Net.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25123.0
4+
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{728C18BC-4085-4492-B0B2-8211CA209A50}"
77
ProjectSection(SolutionItems) = preProject

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ All of our [.NET clients can be installed](https://www.nuget.org/profiles/except
1616

1717
**This section is for development purposes only! If you are trying to use the Exceptionless .NET libraries, please get them from NuGet.**
1818

19-
1. You will need to have [Visual Studio 2015](http://www.visualstudio.com/products/visual-studio-community-vs) installed.
19+
1. You will need to have [Visual Studio 2015](http://www.visualstudio.com/products/visual-studio-community-vs) and [.NET Core SDK with VS Tooling](https://www.microsoft.com/net/core) installed.
2020
2. Open the `Exceptionless.Net.sln` Visual Studio solution file.
2121
3. Select `Exceptionless.SampleConsole` as the startup project.
2222
4. Run the project by pressing `F5` to start the console.

src/Exceptionless.Tests/Plugins/PluginTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,28 @@ public void HandleAggregateExceptionsPlugin_SingleInnerException() {
289289
plugin.Run(context);
290290
Assert.True(context.Cancel);
291291
}
292+
293+
[Fact (Skip = "There is a bug in the .NET Framework where non thrown exceptions with non custom stack traces cannot be computed #116")]
294+
public void CanHandleExceptionWithOverriddenStackTrace() {
295+
var client = CreateClient();
296+
var plugin = new ErrorPlugin();
297+
298+
var context = new EventPluginContext(client, new Event());
299+
context.ContextData.SetException(GetExceptionWithOverriddenStackTrace());
300+
plugin.Run(context);
301+
Assert.False(context.Cancel);
302+
303+
var error = context.Event.GetError();
304+
Assert.True(error.StackTrace.Count > 0);
305+
306+
context.ContextData.SetException(new ExceptionWithOverriddenStackTrace("test"));
307+
plugin.Run(context);
308+
Assert.False(context.Cancel);
292309

310+
error = context.Event.GetError();
311+
Assert.True(error.StackTrace.Count > 0);
312+
}
313+
293314
[Fact]
294315
public void HandleAggregateExceptionsPlugin_MultipleInnerException() {
295316
var submissionClient = new InMemorySubmissionClient();
@@ -703,6 +724,30 @@ public void VerifyDeduplication() {
703724
Thread.Sleep(50);
704725
Assert.Equal(9, mergedContext.Event.Count.GetValueOrDefault());
705726
}
727+
728+
[Fact]
729+
public void VerifyDeduplicationPluginWillCallSubmittingHandler() {
730+
var client = CreateClient();
731+
foreach (var plugin in client.Configuration.Plugins)
732+
client.Configuration.RemovePlugin(plugin.Key);
733+
client.Configuration.AddPlugin(new DuplicateCheckerPlugin(TimeSpan.FromMilliseconds(75)));
734+
735+
int submittingEventHandlerCalls = 0;
736+
client.SubmittingEvent += (sender, args) => {
737+
Interlocked.Increment(ref submittingEventHandlerCalls);
738+
};
739+
740+
for (int index = 0; index < 3; index++) {
741+
client.SubmitLog("test");
742+
if (index > 0)
743+
continue;
744+
745+
Assert.Equal(1, submittingEventHandlerCalls);
746+
}
747+
748+
Thread.Sleep(100);
749+
Assert.Equal(2, submittingEventHandlerCalls);
750+
}
706751

707752
[Fact]
708753
public void VerifyDeduplicationMultithreaded() {
@@ -758,6 +803,14 @@ public void VerifyDeduplicationFromFiles() {
758803
}
759804
}
760805

806+
private ExceptionWithOverriddenStackTrace GetExceptionWithOverriddenStackTrace(string message = "Test") {
807+
try {
808+
throw new ExceptionWithOverriddenStackTrace(message);
809+
} catch (ExceptionWithOverriddenStackTrace ex) {
810+
return ex;
811+
}
812+
}
813+
761814
private Exception GetException(string message = "Test") {
762815
try {
763816
throw new Exception(message);
@@ -816,5 +869,12 @@ public MyApplicationException(string message) : base(message) {
816869

817870
public override IDictionary Data { get { return SetsDataProperty; } }
818871
}
872+
873+
[Serializable]
874+
public class ExceptionWithOverriddenStackTrace : Exception {
875+
private readonly string _stackTrace = Environment.StackTrace;
876+
public ExceptionWithOverriddenStackTrace(string message) : base(message) { }
877+
public override string StackTrace => _stackTrace;
878+
}
819879
}
820880
}

src/Exceptionless/ExceptionlessClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public string GetLastReferenceId() {
233233
/// </summary>
234234
public event EventHandler<EventSubmittingEventArgs> SubmittingEvent;
235235

236-
private bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
236+
protected internal bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
237237
var args = new EventSubmittingEventArgs(this, ev, pluginContextData);
238238
OnSubmittingEvent(args);
239239
return !args.Cancel;
@@ -243,7 +243,7 @@ private bool OnSubmittingEvent(Event ev, ContextData pluginContextData) {
243243
/// Raises the <see cref="SubmittingEvent" /> event.
244244
/// </summary>
245245
/// <param name="e">The <see cref="EventSubmittingEventArgs" /> instance containing the event data.</param>
246-
protected void OnSubmittingEvent(EventSubmittingEventArgs e) {
246+
protected internal void OnSubmittingEvent(EventSubmittingEventArgs e) {
247247
if (SubmittingEvent == null)
248248
return;
249249

@@ -268,7 +268,7 @@ protected void OnSubmittingEvent(EventSubmittingEventArgs e) {
268268
/// Raises the <see cref="SubmittedEvent" /> event.
269269
/// </summary>
270270
/// <param name="e">The <see cref="EventSubmittedEventArgs" /> instance containing the event data.</param>
271-
protected void OnSubmittedEvent(EventSubmittedEventArgs e) {
271+
protected internal void OnSubmittedEvent(EventSubmittedEventArgs e) {
272272
if (SubmittedEvent == null)
273273
return;
274274

src/Exceptionless/Extensions/CollectionEqualityExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static int GetCollectionHashCode<TValue>(this IDictionary<string, TValue>
7575
var item = source[key];
7676
unchecked {
7777
var kvpHash = key.GetHashCode();
78-
kvpHash = (kvpHash * 397) ^ item.GetHashCode();
78+
kvpHash = (kvpHash * 397) ^ (item == null ? 0 : item.GetHashCode());
7979
keyValuePairHashes.Add(kvpHash);
8080
}
8181
}

0 commit comments

Comments
 (0)