Skip to content

Commit 67f467b

Browse files
committed
Fixed #45 Data Exclusions was being ignored on extra exception properties.
1 parent beeb790 commit 67f467b

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

Source/Extras/Extensions/ToErrorModelExtensions.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ internal static class ToErrorModelExtensions {
2828
/// </summary>
2929
/// <param name="exception">The exception to populate properties from.</param>
3030
/// <param name="log">The log implementation used for diagnostic information.</param>
31-
public static Error ToErrorModel(this Exception exception, IExceptionlessLog log) {
32-
return ToErrorModelInternal(exception, log);
31+
/// <param name="dataExclusions">Data exclusions that get run on extra exception properties.</param>
32+
public static Error ToErrorModel(this Exception exception, IExceptionlessLog log, IEnumerable<string> dataExclusions) {
33+
return ToErrorModelInternal(exception, log, dataExclusions);
3334
}
3435

35-
private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog log, bool isInner = false) {
36+
private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog log, IEnumerable<string> dataExclusions, bool isInner = false) {
3637
Type type = exception.GetType();
3738

3839
var error = new Error {
@@ -61,7 +62,8 @@ private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog
6162
}
6263

6364
try {
64-
Dictionary<string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
65+
var exclusions = _exceptionExclusions.Union(dataExclusions ?? new List<string>());
66+
var extraProperties = type.GetPublicProperties().Where(p => !exclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
6567
try {
6668
return p.GetValue(exception, null);
6769
} catch { }
@@ -81,7 +83,7 @@ private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog
8183
} catch { }
8284

8385
if (exception.InnerException != null)
84-
error.Inner = ToErrorModelInternal(exception.InnerException, log, true);
86+
error.Inner = ToErrorModelInternal(exception.InnerException, log, dataExclusions, true);
8587

8688
return error;
8789
}
@@ -173,8 +175,12 @@ private static void PopulateStackTrace(this Error error, Error root, Exception e
173175
FileName = frame.GetFileName()
174176
};
175177

176-
stackFrame.Data["ILOffset"] = frame.GetILOffset();
177-
stackFrame.Data["NativeOffset"] = frame.GetNativeOffset();
178+
try {
179+
stackFrame.Data["ILOffset"] = frame.GetILOffset();
180+
stackFrame.Data["NativeOffset"] = frame.GetNativeOffset();
181+
} catch (Exception ex) {
182+
log.Error(typeof(ExceptionlessClient), ex, "Error populating StackFrame offset info: " + ex.Message);
183+
}
178184

179185
try {
180186
stackFrame.PopulateMethod(root, frame.GetMethod());

Source/Extras/Plugins/ErrorPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void Run(EventPluginContext context) {
1111
return;
1212

1313
context.Event.Type = Event.KnownTypes.Error;
14-
context.Event.Data[Event.KnownDataKeys.Error] = exception.ToErrorModel(context.Log);
14+
context.Event.Data[Event.KnownDataKeys.Error] = exception.ToErrorModel(context.Log, context.Client.Configuration.DataExclusions);
1515
}
1616
}
1717
}

Source/Shared/Extensions/ToSimpleErrorModelExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using Exceptionless.Logging;
56
using Exceptionless.Models.Data;
67

78
namespace Exceptionless.Extensions {
@@ -12,7 +13,13 @@ internal static class ToSimpleErrorModelExtensions {
1213
"Entries", "StateEntries", "PersistedState", "Results"
1314
};
1415

15-
public static SimpleError ToSimpleErrorModel(this Exception exception) {
16+
/// <summary>
17+
/// Sets the properties from an exception.
18+
/// </summary>
19+
/// <param name="exception">The exception to populate properties from.</param>
20+
/// <param name="log">The log implementation used for diagnostic information.</param>
21+
/// <param name="dataExclusions">Data exclusions that get run on extra exception properties.</param>
22+
public static SimpleError ToSimpleErrorModel(this Exception exception, IExceptionlessLog log, IEnumerable<string> dataExclusions) {
1623
Type type = exception.GetType();
1724

1825
var error = new SimpleError {
@@ -22,7 +29,8 @@ public static SimpleError ToSimpleErrorModel(this Exception exception) {
2229
};
2330

2431
try {
25-
Dictionary<string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
32+
var exclusions = _exceptionExclusions.Union(dataExclusions ?? new List<string>());
33+
var extraProperties = type.GetPublicProperties().Where(p => !exclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
2634
try {
2735
return p.GetValue(exception, null);
2836
} catch {}
@@ -42,7 +50,7 @@ public static SimpleError ToSimpleErrorModel(this Exception exception) {
4250
} catch {}
4351

4452
if (exception.InnerException != null)
45-
error.Inner = exception.InnerException.ToSimpleErrorModel();
53+
error.Inner = exception.InnerException.ToSimpleErrorModel(log, dataExclusions);
4654

4755
return error;
4856
}

Source/Shared/Plugins/Default/EnvironmentInfoPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void Run(EventPluginContext context) {
1818

1919
var info = collector.GetEnvironmentInfo();
2020
info.InstallId = context.Client.Configuration.GetInstallId();
21-
context.Event.Data.Add(Event.KnownDataKeys.EnvironmentInfo, info);
21+
context.Event.Data[Event.KnownDataKeys.EnvironmentInfo] = info;
2222
} catch (Exception ex) {
2323
context.Log.FormattedError(typeof(EnvironmentInfoPlugin), ex, "Error adding environment information: {0}", ex.Message);
2424
}

Source/Shared/Plugins/Default/SimpleErrorPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void Run(EventPluginContext context) {
1111
return;
1212

1313
context.Event.Type = Event.KnownTypes.Error;
14-
context.Event.Data[Event.KnownDataKeys.SimpleError] = exception.ToSimpleErrorModel();
14+
context.Event.Data[Event.KnownDataKeys.SimpleError] = exception.ToSimpleErrorModel(context.Log, context.Client.Configuration.DataExclusions);
1515
}
1616
}
1717
}

Source/Shared/Plugins/Default/SubmissionMethodPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class SubmissionMethodPlugin : IEventPlugin {
77
public void Run(EventPluginContext context) {
88
string submissionMethod = context.ContextData.GetSubmissionMethod();
99
if (!String.IsNullOrEmpty(submissionMethod))
10-
context.Event.AddObject(submissionMethod, Event.KnownDataKeys.SubmissionMethod);
10+
context.Event.Data[Event.KnownDataKeys.SubmissionMethod] = submissionMethod;
1111
}
1212
}
1313
}

0 commit comments

Comments
 (0)