From 5a5312cc082ccd880b65165135e05b4f3b035df7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Silva?=
<2493377+askpt@users.noreply.github.com>
Date: Fri, 5 Apr 2024 18:32:24 +0100
Subject: [PATCH] chore!: Enable nullable reference types (#253)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## Enable nullable reference types
- This PR enables the nullable validation and treats warnings as errors.
### Related Issues
Fixes #208
### Notes
This PR turns on the nullable checks for the dotnet checks. This gives
us a better and safer codebase since it checks for potential null
exceptions.
### Breaking changes
While this PR won't require changes to the exposed API, it might show
some errors to the clients consuming it.
---------
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
---
build/Common.props | 2 +
src/OpenFeature/Api.cs | 12 +-
.../Error/FeatureProviderException.cs | 2 +-
.../Error/FlagNotFoundException.cs | 2 +-
src/OpenFeature/Error/GeneralException.cs | 2 +-
.../Error/InvalidContextException.cs | 2 +-
src/OpenFeature/Error/ParseErrorException.cs | 2 +-
.../Error/ProviderNotReadyException.cs | 2 +-
.../Error/TargetingKeyMissingException.cs | 2 +-
.../Error/TypeMismatchException.cs | 2 +-
src/OpenFeature/EventExecutor.cs | 36 ++---
src/OpenFeature/Extension/EnumExtensions.cs | 2 +-
src/OpenFeature/FeatureProvider.cs | 10 +-
src/OpenFeature/Hook.cs | 8 +-
src/OpenFeature/IFeatureClient.cs | 20 +--
src/OpenFeature/Model/BaseMetadata.cs | 1 -
src/OpenFeature/Model/ClientMetadata.cs | 4 +-
src/OpenFeature/Model/EvaluationContext.cs | 6 +-
.../Model/EvaluationContextBuilder.cs | 4 +-
.../Model/FlagEvaluationDetails.cs | 12 +-
.../Model/FlagEvaluationOptions.cs | 4 +-
src/OpenFeature/Model/FlagMetadata.cs | 1 -
src/OpenFeature/Model/HookContext.cs | 8 +-
src/OpenFeature/Model/Metadata.cs | 4 +-
src/OpenFeature/Model/ProviderEvents.cs | 10 +-
src/OpenFeature/Model/ResolutionDetails.cs | 12 +-
src/OpenFeature/Model/Structure.cs | 2 +-
src/OpenFeature/Model/Value.cs | 10 +-
src/OpenFeature/NoOpProvider.cs | 10 +-
src/OpenFeature/OpenFeatureClient.cs | 56 +++----
src/OpenFeature/ProviderRepository.cs | 59 ++++---
src/OpenFeature/Providers/Memory/Flag.cs | 1 -
.../Providers/Memory/InMemoryProvider.cs | 1 -
.../Steps/EvaluationStepDefinitions.cs | 144 +++++++++---------
.../FeatureProviderExceptionTests.cs | 32 ++++
test/OpenFeature.Tests/FlagMetadataTest.cs | 1 -
.../OpenFeatureClientTests.cs | 8 +-
.../OpenFeatureEvaluationContextTests.cs | 20 ++-
.../OpenFeatureEventTests.cs | 72 ++++++---
test/OpenFeature.Tests/OpenFeatureTests.cs | 14 +-
.../ProviderRepositoryTests.cs | 16 +-
.../Providers/Memory/InMemoryProviderTests.cs | 10 +-
test/OpenFeature.Tests/StructureTests.cs | 4 +-
test/OpenFeature.Tests/TestImplementations.cs | 18 +--
test/OpenFeature.Tests/ValueTests.cs | 108 ++++++++++++-
45 files changed, 486 insertions(+), 272 deletions(-)
diff --git a/build/Common.props b/build/Common.props
index b1857e0d..9f807b2c 100644
--- a/build/Common.props
+++ b/build/Common.props
@@ -6,6 +6,8 @@
true
EnableGenerateDocumentationFile
+ enable
+ true
diff --git a/src/OpenFeature/Api.cs b/src/OpenFeature/Api.cs
index af302e7e..6dc0f863 100644
--- a/src/OpenFeature/Api.cs
+++ b/src/OpenFeature/Api.cs
@@ -54,7 +54,7 @@ public void SetProvider(FeatureProvider featureProvider)
///
/// The provider cannot be set to null. Attempting to set the provider to null has no effect.
/// Implementation of
- public async Task SetProviderAsync(FeatureProvider featureProvider)
+ public async Task SetProviderAsync(FeatureProvider? featureProvider)
{
this._eventExecutor.RegisterDefaultFeatureProvider(featureProvider);
await this._repository.SetProvider(featureProvider, this.GetContext()).ConfigureAwait(false);
@@ -80,6 +80,10 @@ public void SetProvider(string clientName, FeatureProvider featureProvider)
/// Implementation of
public async Task SetProviderAsync(string clientName, FeatureProvider featureProvider)
{
+ if (string.IsNullOrWhiteSpace(clientName))
+ {
+ throw new ArgumentNullException(nameof(clientName));
+ }
this._eventExecutor.RegisterClientFeatureProvider(clientName, featureProvider);
await this._repository.SetProvider(clientName, featureProvider, this.GetContext()).ConfigureAwait(false);
}
@@ -138,8 +142,8 @@ public FeatureProvider GetProvider(string clientName)
/// Logger instance used by client
/// Context given to this client
///
- public FeatureClient GetClient(string name = null, string version = null, ILogger logger = null,
- EvaluationContext context = null) =>
+ public FeatureClient GetClient(string? name = null, string? version = null, ILogger? logger = null,
+ EvaluationContext? context = null) =>
new FeatureClient(name, version, logger, context);
///
@@ -200,7 +204,7 @@ public void AddHooks(IEnumerable hooks)
/// Sets the global
///
/// The to set
- public void SetContext(EvaluationContext context)
+ public void SetContext(EvaluationContext? context)
{
this._evaluationContextLock.EnterWriteLock();
try
diff --git a/src/OpenFeature/Error/FeatureProviderException.cs b/src/OpenFeature/Error/FeatureProviderException.cs
index df74afa4..b2c43dc7 100644
--- a/src/OpenFeature/Error/FeatureProviderException.cs
+++ b/src/OpenFeature/Error/FeatureProviderException.cs
@@ -20,7 +20,7 @@ public class FeatureProviderException : Exception
/// Common error types
/// Exception message
/// Optional inner exception
- public FeatureProviderException(ErrorType errorType, string message = null, Exception innerException = null)
+ public FeatureProviderException(ErrorType errorType, string? message = null, Exception? innerException = null)
: base(message, innerException)
{
this.ErrorType = errorType;
diff --git a/src/OpenFeature/Error/FlagNotFoundException.cs b/src/OpenFeature/Error/FlagNotFoundException.cs
index 6b8fb4bb..b1a5b64a 100644
--- a/src/OpenFeature/Error/FlagNotFoundException.cs
+++ b/src/OpenFeature/Error/FlagNotFoundException.cs
@@ -15,7 +15,7 @@ public class FlagNotFoundException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public FlagNotFoundException(string message = null, Exception innerException = null)
+ public FlagNotFoundException(string? message = null, Exception? innerException = null)
: base(ErrorType.FlagNotFound, message, innerException)
{
}
diff --git a/src/OpenFeature/Error/GeneralException.cs b/src/OpenFeature/Error/GeneralException.cs
index 42e0fe73..4580ff31 100644
--- a/src/OpenFeature/Error/GeneralException.cs
+++ b/src/OpenFeature/Error/GeneralException.cs
@@ -15,7 +15,7 @@ public class GeneralException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public GeneralException(string message = null, Exception innerException = null)
+ public GeneralException(string? message = null, Exception? innerException = null)
: base(ErrorType.General, message, innerException)
{
}
diff --git a/src/OpenFeature/Error/InvalidContextException.cs b/src/OpenFeature/Error/InvalidContextException.cs
index 6bcc8051..ffea8ab1 100644
--- a/src/OpenFeature/Error/InvalidContextException.cs
+++ b/src/OpenFeature/Error/InvalidContextException.cs
@@ -15,7 +15,7 @@ public class InvalidContextException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public InvalidContextException(string message = null, Exception innerException = null)
+ public InvalidContextException(string? message = null, Exception? innerException = null)
: base(ErrorType.InvalidContext, message, innerException)
{
}
diff --git a/src/OpenFeature/Error/ParseErrorException.cs b/src/OpenFeature/Error/ParseErrorException.cs
index 7b3d21e9..81ded456 100644
--- a/src/OpenFeature/Error/ParseErrorException.cs
+++ b/src/OpenFeature/Error/ParseErrorException.cs
@@ -15,7 +15,7 @@ public class ParseErrorException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public ParseErrorException(string message = null, Exception innerException = null)
+ public ParseErrorException(string? message = null, Exception? innerException = null)
: base(ErrorType.ParseError, message, innerException)
{
}
diff --git a/src/OpenFeature/Error/ProviderNotReadyException.cs b/src/OpenFeature/Error/ProviderNotReadyException.cs
index c3c8b5d0..ca509692 100644
--- a/src/OpenFeature/Error/ProviderNotReadyException.cs
+++ b/src/OpenFeature/Error/ProviderNotReadyException.cs
@@ -15,7 +15,7 @@ public class ProviderNotReadyException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public ProviderNotReadyException(string message = null, Exception innerException = null)
+ public ProviderNotReadyException(string? message = null, Exception? innerException = null)
: base(ErrorType.ProviderNotReady, message, innerException)
{
}
diff --git a/src/OpenFeature/Error/TargetingKeyMissingException.cs b/src/OpenFeature/Error/TargetingKeyMissingException.cs
index 632cc791..71742413 100644
--- a/src/OpenFeature/Error/TargetingKeyMissingException.cs
+++ b/src/OpenFeature/Error/TargetingKeyMissingException.cs
@@ -15,7 +15,7 @@ public class TargetingKeyMissingException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public TargetingKeyMissingException(string message = null, Exception innerException = null)
+ public TargetingKeyMissingException(string? message = null, Exception? innerException = null)
: base(ErrorType.TargetingKeyMissing, message, innerException)
{
}
diff --git a/src/OpenFeature/Error/TypeMismatchException.cs b/src/OpenFeature/Error/TypeMismatchException.cs
index 96c23872..83ff0cf3 100644
--- a/src/OpenFeature/Error/TypeMismatchException.cs
+++ b/src/OpenFeature/Error/TypeMismatchException.cs
@@ -15,7 +15,7 @@ public class TypeMismatchException : FeatureProviderException
///
/// Exception message
/// Optional inner exception
- public TypeMismatchException(string message = null, Exception innerException = null)
+ public TypeMismatchException(string? message = null, Exception? innerException = null)
: base(ErrorType.TypeMismatch, message, innerException)
{
}
diff --git a/src/OpenFeature/EventExecutor.cs b/src/OpenFeature/EventExecutor.cs
index 7bdfeb6e..a80c92d4 100644
--- a/src/OpenFeature/EventExecutor.cs
+++ b/src/OpenFeature/EventExecutor.cs
@@ -14,7 +14,7 @@ internal class EventExecutor : IAsyncDisposable
{
private readonly object _lockObj = new object();
public readonly Channel