Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ internal class SystemWebRequestEventProcessor : ISentryEventProcessor

public SystemWebRequestEventProcessor(IRequestPayloadExtractor payloadExtractor, SentryOptions options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
PayloadExtractor = payloadExtractor ?? throw new ArgumentNullException(nameof(payloadExtractor));
ArgumentNullException.ThrowIfNull(payloadExtractor);
ArgumentNullException.ThrowIfNull(options);

_options = options;
PayloadExtractor = payloadExtractor;
}

public SentryEvent? Process(SentryEvent? @event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public class ProtobufRequestExtractionDispatcher : IProtobufRequestPayloadExtrac
public ProtobufRequestExtractionDispatcher(IEnumerable<IProtobufRequestPayloadExtractor> extractors,
SentryOptions options, Func<RequestSize> sizeSwitch)
{
Extractors = extractors ?? throw new ArgumentNullException(nameof(extractors));
_options = options ?? throw new ArgumentNullException(nameof(options));
_sizeSwitch = sizeSwitch ?? throw new ArgumentNullException(nameof(sizeSwitch));
ArgumentNullException.ThrowIfNull(extractors);
ArgumentNullException.ThrowIfNull(options);
ArgumentNullException.ThrowIfNull(sizeSwitch);

Extractors = extractors;
_options = options;
_sizeSwitch = sizeSwitch;
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry.AspNetCore.Grpc/SentryGrpcInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public SentryGrpcInterceptor(
Func<IHub> hubAccessor,
IOptions<SentryAspNetCoreOptions> options)
{
_hubAccessor = hubAccessor ?? throw new ArgumentNullException(nameof(hubAccessor));
ArgumentNullException.ThrowIfNull(hubAccessor);

_hubAccessor = hubAccessor;
_options = options.Value;
var hub = _hubAccessor();
foreach (var callback in _options.ConfigureScopeCallbacks)
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry.AspNetCore/SentryAspNetCoreBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal class SentryAspNetCoreBuilder : ISentryBuilder

public SentryAspNetCoreBuilder(IServiceCollection services)
{
Services = services ?? throw new ArgumentNullException(nameof(services));
ArgumentNullException.ThrowIfNull(services);

Services = services;
}
}
4 changes: 3 additions & 1 deletion src/Sentry.AspNetCore/SentryMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public SentryMiddleware(
IEnumerable<ISentryEventProcessor> eventProcessors,
IEnumerable<ISentryTransactionProcessor> transactionProcessors)
{
_getHub = getHub ?? throw new ArgumentNullException(nameof(getHub));
ArgumentNullException.ThrowIfNull(getHub);

_getHub = getHub;
_options = options.Value;
_hostingEnvironment = hostingEnvironment;
_logger = logger;
Expand Down
6 changes: 5 additions & 1 deletion src/Sentry.Extensions.Logging/DelegateLogEntryFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ public class DelegateLogEntryFilter : ILogEntryFilter
/// </summary>
/// <param name="filter"></param>
public DelegateLogEntryFilter(Func<string, LogLevel, EventId, Exception?, bool> filter)
=> _filter = filter ?? throw new ArgumentNullException(nameof(filter));
{
ArgumentNullException.ThrowIfNull(filter);

_filter = filter;
}

/// <inheritdoc />
public bool Filter(
Expand Down
10 changes: 7 additions & 3 deletions src/Sentry/Extensibility/RequestBodyExtractionDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ public class RequestBodyExtractionDispatcher : IRequestPayloadExtractor
/// <param name="sizeSwitch">The max request size to capture.</param>
public RequestBodyExtractionDispatcher(IEnumerable<IRequestPayloadExtractor> extractors, SentryOptions options, Func<RequestSize> sizeSwitch)
{
Extractors = extractors ?? throw new ArgumentNullException(nameof(extractors));
_options = options ?? throw new ArgumentNullException(nameof(options));
_sizeSwitch = sizeSwitch ?? throw new ArgumentNullException(nameof(sizeSwitch));
ArgumentNullException.ThrowIfNull(extractors);
ArgumentNullException.ThrowIfNull(options);
ArgumentNullException.ThrowIfNull(sizeSwitch);

Extractors = extractors;
_options = options;
_sizeSwitch = sizeSwitch;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ internal class DefaultSentryHttpClientFactory : ISentryHttpClientFactory
/// <param name="options">The HTTP options.</param>
public HttpClient Create(SentryOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);

var handler = options.CreateHttpMessageHandler?.Invoke() ?? new HttpClientHandler();
if (handler is HttpClientHandler httpClientHandler)
Expand Down
6 changes: 5 additions & 1 deletion src/Sentry/Internal/Http/RetryAfterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public RetryAfterHandler(HttpMessageHandler innerHandler)

internal RetryAfterHandler(HttpMessageHandler innerHandler, ISystemClock clock)
: base(innerHandler)
=> _clock = clock ?? throw new ArgumentNullException(nameof(clock));
{
ArgumentNullException.ThrowIfNull(clock);

_clock = clock;
}

/// <summary>
/// Sends an HTTP request to the inner handler while verifying the Response status code for HTTP 429.
Expand Down
28 changes: 24 additions & 4 deletions src/Sentry/Internal/Polyfills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ internal static class EnumerableExtensions
{
internal static bool TryGetNonEnumeratedCount<TSource>(this IEnumerable<TSource> source, out int count)
{
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (source is ICollection<TSource> genericCollection)
{
Expand All @@ -91,3 +88,26 @@ internal static bool TryGetNonEnumeratedCount<TSource>(this IEnumerable<TSource>
}
}
#endif

// TODO: remove when updating Polyfill: https://github.com/getsentry/sentry-dotnet/pull/4879
#if !NET6_0_OR_GREATER
internal static class ArgumentNullExceptionExtensions
{
extension(ArgumentNullException)
{
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
Throw(paramName);
}
}
}

[DoesNotReturn]
private static void Throw(string? paramName)
{
throw new ArgumentNullException(paramName);
}
}
#endif
4 changes: 3 additions & 1 deletion src/Sentry/Internal/SdkComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ internal class SdkComposer

public SdkComposer(SentryOptions options, BackpressureMonitor? backpressureMonitor)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
ArgumentNullException.ThrowIfNull(options);

_options = options;
if (options.Dsn is null)
{
throw new ArgumentException("No DSN defined in the SentryOptions");
Expand Down
4 changes: 3 additions & 1 deletion src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ internal SentryClient(
ISessionManager? sessionManager = null,
BackpressureMonitor? backpressureMonitor = null)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
ArgumentNullException.ThrowIfNull(options);

_options = options;
_backpressureMonitor = backpressureMonitor;
_randomValuesFactory = randomValuesFactory ?? new SynchronizedRandomValuesFactory();
_sessionManager = sessionManager ?? new GlobalSessionManager(options);
Expand Down
14 changes: 5 additions & 9 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,7 @@ public StackTraceMode StackTraceMode
public void AddJsonConverter(JsonConverter converter)
{
// protect against null because user may not have nullability annotations enabled
if (converter == null!)
{
throw new ArgumentNullException(nameof(converter));
}
ArgumentNullException.ThrowIfNull(converter);

JsonExtensions.AddJsonConverter(converter);
}
Expand All @@ -1228,10 +1225,7 @@ public void AddJsonSerializerContext<T>(Func<JsonSerializerOptions, T> contextBu
where T : JsonSerializerContext
{
// protect against null because user may not have nullability annotations enabled
if (contextBuilder == null!)
{
throw new ArgumentNullException(nameof(contextBuilder));
}
ArgumentNullException.ThrowIfNull(contextBuilder);

JsonExtensions.AddJsonSerializerContext(contextBuilder);
}
Expand Down Expand Up @@ -1717,7 +1711,9 @@ public IEnumerable<ISentryEventExceptionProcessor> GetAllExceptionProcessors()
/// <param name="sentryStackTraceFactory">The stack trace factory.</param>
public SentryOptions UseStackTraceFactory(ISentryStackTraceFactory sentryStackTraceFactory)
{
SentryStackTraceFactory = sentryStackTraceFactory ?? throw new ArgumentNullException(nameof(sentryStackTraceFactory));
ArgumentNullException.ThrowIfNull(sentryStackTraceFactory);

SentryStackTraceFactory = sentryStackTraceFactory;
return this;
}

Expand Down
11 changes: 2 additions & 9 deletions test/Sentry.Tests/Protocol/DsnTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,8 @@ public override string ToString()

private static void AssertEqual(DsnTestCase @case, Dsn dsn)
{
if (@case == null)
{
throw new ArgumentNullException(nameof(@case));
}

if (dsn == null)
{
throw new ArgumentNullException(nameof(dsn));
}
Assert.NotNull(@case);
Assert.NotNull(dsn);

var uri = dsn.GetStoreEndpointUri();

Expand Down
Loading