Skip to content

Commit 02b1022

Browse files
committed
Fixed #112 Throw ArgumentNullExceptions on null ExceptionlessClient extension methods.
1 parent a433bd7 commit 02b1022

File tree

10 files changed

+66
-0
lines changed

10 files changed

+66
-0
lines changed

src/Exceptionless/Extensions/ExceptionlessClientExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ public static void UnregisterOnProcessExitHandler(this ExceptionlessClient clien
344344

345345
private static EventHandler<UnobservedTaskExceptionEventArgs> _onTaskSchedulerOnUnobservedTaskException;
346346
public static void RegisterTaskSchedulerUnobservedTaskExceptionHandler(this ExceptionlessClient client) {
347+
if (client == null)
348+
throw new ArgumentNullException(nameof(client));
349+
347350
if (_onTaskSchedulerOnUnobservedTaskException == null) {
348351
_onTaskSchedulerOnUnobservedTaskException = (sender, args) => {
349352
var contextData = new ContextData();
@@ -363,6 +366,9 @@ public static void RegisterTaskSchedulerUnobservedTaskExceptionHandler(this Exce
363366
}
364367

365368
public static void UnregisterTaskSchedulerUnobservedTaskExceptionHandler(this ExceptionlessClient client) {
369+
if (client == null)
370+
throw new ArgumentNullException(nameof(client));
371+
366372
if (_onTaskSchedulerOnUnobservedTaskException == null)
367373
return;
368374

src/Platforms/Exceptionless.Log4net/ExceptionlessClientExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace Exceptionless.Log4net {
99
public static class ExceptionlessClientExtensions {
1010
public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LoggingEvent ev) {
11+
if (client == null)
12+
throw new ArgumentNullException(nameof(client));
13+
1114
var builder = ev.ExceptionObject != null ? client.CreateException(ev.ExceptionObject) : client.CreateLog(ev.LoggerName, ev.RenderedMessage, ev.Level.ToLogLevel());
1215
builder.Target.Date = ev.TimeStamp;
1316

@@ -48,6 +51,9 @@ public static LogLevel ToLogLevel(this Level level) {
4851
}
4952

5053
public static void SubmitFromLogEvent(this ExceptionlessClient client, LoggingEvent ev) {
54+
if (client == null)
55+
throw new ArgumentNullException(nameof(client));
56+
5157
CreateFromLogEvent(client, ev).Submit();
5258
}
5359

src/Platforms/Exceptionless.NLog/ExceptionlessClientExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace Exceptionless.NLog {
99
public static class ExceptionlessClientExtensions {
1010
public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LogEventInfo ev) {
11+
if (client == null)
12+
throw new ArgumentNullException(nameof(client));
13+
1114
var contextData = new ContextData(ev.GetContextData());
1215

1316
if (ev.Exception != null)
@@ -54,6 +57,9 @@ public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, L
5457
}
5558

5659
public static void SubmitFromLogEvent(this ExceptionlessClient client, LogEventInfo ev) {
60+
if (client == null)
61+
throw new ArgumentNullException(nameof(client));
62+
5763
CreateFromLogEvent(client, ev).Submit();
5864
}
5965

src/Platforms/Exceptionless.Nancy/ExceptionlessNancyExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public static class ExceptionlessNancyExtensions {
1919
/// <param name="client">The ExceptionlessClient.</param>
2020
/// <param name="pipelines">The IPipelines instance.</param>
2121
public static void RegisterNancy(this ExceptionlessClient client, IPipelines pipelines) {
22+
if (client == null)
23+
throw new ArgumentNullException(nameof(client));
24+
2225
client.Startup();
2326
client.Configuration.AddPlugin<ExceptionlessNancyPlugin>();
2427
client.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
@@ -32,6 +35,9 @@ public static void RegisterNancy(this ExceptionlessClient client, IPipelines pip
3235
/// </summary>
3336
/// <param name="client">The ExceptionlessClient.</param>
3437
public static void UnregisterNancy(this ExceptionlessClient client) {
38+
if (client == null)
39+
throw new ArgumentNullException(nameof(client));
40+
3541
client.Shutdown();
3642
client.Configuration.RemovePlugin<ExceptionlessNancyPlugin>();
3743
}

src/Platforms/Exceptionless.Web/ExceptionlessClientExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public static class ExceptionlessClientExtensions {
99
private static EventHandler _onHttpApplicationError;
1010

1111
public static void RegisterHttpApplicationErrorHandler(this ExceptionlessClient client, HttpApplication app) {
12+
if (client == null)
13+
throw new ArgumentNullException(nameof(client));
14+
1215
if (_onHttpApplicationError == null)
1316
_onHttpApplicationError = (sender, args) => {
1417
if (HttpContext.Current == null)
@@ -35,6 +38,9 @@ public static void RegisterHttpApplicationErrorHandler(this ExceptionlessClient
3538
}
3639

3740
public static void UnregisterHttpApplicationErrorExceptionHandler(this ExceptionlessClient client, HttpApplication app) {
41+
if (client == null)
42+
throw new ArgumentNullException(nameof(client));
43+
3844
if (_onHttpApplicationError == null)
3945
return;
4046

src/Platforms/Exceptionless.WebApi/ExceptionlessWebApiExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public static class ExceptionlessWebApiExtensions {
1919
/// <param name="client">The ExceptionlessClient.</param>
2020
/// <param name="config">The HttpConfiguration instance.</param>
2121
public static void RegisterWebApi(this ExceptionlessClient client, HttpConfiguration config) {
22+
if (client == null)
23+
throw new ArgumentNullException(nameof(client));
24+
2225
client.Startup();
2326
client.Configuration.AddPlugin<ExceptionlessWebApiPlugin>();
2427
client.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
@@ -33,6 +36,9 @@ public static void RegisterWebApi(this ExceptionlessClient client, HttpConfigura
3336
/// </summary>
3437
/// <param name="client">The ExceptionlessClient.</param>
3538
public static void UnregisterWebApi(this ExceptionlessClient client) {
39+
if (client == null)
40+
throw new ArgumentNullException(nameof(client));
41+
3642
client.Shutdown();
3743
client.Configuration.RemovePlugin<ExceptionlessWebApiPlugin>();
3844
}

src/Platforms/Exceptionless.Windows/ExceptionlessClientExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public static class ExceptionlessClientExtensions {
1010
private static ThreadExceptionEventHandler _onApplicationThreadException;
1111

1212
public static void RegisterApplicationThreadExceptionHandler(this ExceptionlessClient client) {
13+
if (client == null)
14+
throw new ArgumentNullException(nameof(client));
15+
1316
if (_onApplicationThreadException == null)
1417
_onApplicationThreadException = (sender, args) => {
1518
var contextData = new ContextData();
@@ -28,6 +31,9 @@ public static void RegisterApplicationThreadExceptionHandler(this ExceptionlessC
2831
}
2932

3033
public static void UnregisterApplicationThreadExceptionHandler(this ExceptionlessClient client) {
34+
if (client == null)
35+
throw new ArgumentNullException(nameof(client));
36+
3137
if (_onApplicationThreadException == null)
3238
return;
3339

src/Platforms/Exceptionless.Windows/ExceptionlessWindowsExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public static class ExceptionlessWindowsExtensions {
1414
/// <param name="client">The ExceptionlessClient.</param>
1515
/// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
1616
public static void Register(this ExceptionlessClient client, bool showDialog = true) {
17+
if (client == null)
18+
throw new ArgumentNullException(nameof(client));
19+
1720
client.Configuration.AddPlugin<SetEnvironmentUserPlugin>();
1821
client.Startup();
1922

@@ -34,6 +37,9 @@ public static void Register(this ExceptionlessClient client, bool showDialog = t
3437
/// </summary>
3538
/// <param name="client">The ExceptionlessClient.</param>
3639
public static void Unregister(this ExceptionlessClient client) {
40+
if (client == null)
41+
throw new ArgumentNullException(nameof(client));
42+
3743
client.Shutdown();
3844
client.UnregisterApplicationThreadExceptionHandler();
3945

src/Platforms/Exceptionless.Wpf/ExceptionlessClientExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public static class ExceptionlessClientExtensions {
1010
private static ThreadExceptionEventHandler _onApplicationThreadException;
1111

1212
public static void RegisterApplicationThreadExceptionHandler(this ExceptionlessClient client) {
13+
if (client == null)
14+
throw new ArgumentNullException(nameof(client));
15+
1316
if (_onApplicationThreadException == null)
1417
_onApplicationThreadException = (sender, args) => {
1518
var contextData = new ContextData();
@@ -28,6 +31,9 @@ public static void RegisterApplicationThreadExceptionHandler(this ExceptionlessC
2831
}
2932

3033
public static void UnregisterApplicationThreadExceptionHandler(this ExceptionlessClient client) {
34+
if (client == null)
35+
throw new ArgumentNullException(nameof(client));
36+
3137
if (_onApplicationThreadException == null)
3238
return;
3339

@@ -38,6 +44,9 @@ public static void UnregisterApplicationThreadExceptionHandler(this Exceptionles
3844
private static DispatcherUnhandledExceptionEventHandler _onApplicationDispatcherUnhandledException;
3945

4046
public static void RegisterApplicationDispatcherUnhandledExceptionHandler(this ExceptionlessClient client) {
47+
if (client == null)
48+
throw new ArgumentNullException(nameof(client));
49+
4150
if (System.Windows.Application.Current == null)
4251
return;
4352

@@ -60,6 +69,9 @@ public static void RegisterApplicationDispatcherUnhandledExceptionHandler(this E
6069
}
6170

6271
public static void UnregisterApplicationDispatcherUnhandledExceptionHandler(this ExceptionlessClient client) {
72+
if (client == null)
73+
throw new ArgumentNullException(nameof(client));
74+
6375
if (_onApplicationDispatcherUnhandledException == null)
6476
return;
6577

src/Platforms/Exceptionless.Wpf/ExceptionlessWpfExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public static class ExceptionlessWpfExtensions {
1515
/// <param name="client">The ExceptionlessClient.</param>
1616
/// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
1717
public static void Register(this ExceptionlessClient client, bool showDialog = true) {
18+
if (client == null)
19+
throw new ArgumentNullException(nameof(client));
20+
1821
client.Configuration.AddPlugin<SetEnvironmentUserPlugin>();
1922
client.Startup();
2023

@@ -36,6 +39,9 @@ public static void Register(this ExceptionlessClient client, bool showDialog = t
3639
/// </summary>
3740
/// <param name="client">The ExceptionlessClient.</param>
3841
public static void Unregister(this ExceptionlessClient client) {
42+
if (client == null)
43+
throw new ArgumentNullException(nameof(client));
44+
3945
client.Shutdown();
4046
client.UnregisterApplicationThreadExceptionHandler();
4147
client.UnregisterApplicationDispatcherUnhandledExceptionHandler();

0 commit comments

Comments
 (0)