Skip to content

Commit 5a5312c

Browse files
authored
chore!: Enable nullable reference types (#253)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## Enable nullable reference types <!-- add the description of the PR here --> - This PR enables the nullable validation and treats warnings as errors. ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> Fixes #208 ### Notes <!-- any additional notes for this PR --> 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 <[email protected]>
1 parent 9b9c3fd commit 5a5312c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+486
-272
lines changed

build/Common.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
77
<!-- Workaround for IDE0005 (Remove unnecessary usings/imports); see https://github.com/dotnet/roslyn/issues/41640 -->
88
<NoWarn>EnableGenerateDocumentationFile</NoWarn>
9+
<Nullable>enable</Nullable>
10+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
911
</PropertyGroup>
1012

1113
<PropertyGroup Condition="'$(Configuration)'=='Debug'">

src/OpenFeature/Api.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void SetProvider(FeatureProvider featureProvider)
5454
/// </summary>
5555
/// <remarks>The provider cannot be set to null. Attempting to set the provider to null has no effect.</remarks>
5656
/// <param name="featureProvider">Implementation of <see cref="FeatureProvider"/></param>
57-
public async Task SetProviderAsync(FeatureProvider featureProvider)
57+
public async Task SetProviderAsync(FeatureProvider? featureProvider)
5858
{
5959
this._eventExecutor.RegisterDefaultFeatureProvider(featureProvider);
6060
await this._repository.SetProvider(featureProvider, this.GetContext()).ConfigureAwait(false);
@@ -80,6 +80,10 @@ public void SetProvider(string clientName, FeatureProvider featureProvider)
8080
/// <param name="featureProvider">Implementation of <see cref="FeatureProvider"/></param>
8181
public async Task SetProviderAsync(string clientName, FeatureProvider featureProvider)
8282
{
83+
if (string.IsNullOrWhiteSpace(clientName))
84+
{
85+
throw new ArgumentNullException(nameof(clientName));
86+
}
8387
this._eventExecutor.RegisterClientFeatureProvider(clientName, featureProvider);
8488
await this._repository.SetProvider(clientName, featureProvider, this.GetContext()).ConfigureAwait(false);
8589
}
@@ -138,8 +142,8 @@ public FeatureProvider GetProvider(string clientName)
138142
/// <param name="logger">Logger instance used by client</param>
139143
/// <param name="context">Context given to this client</param>
140144
/// <returns><see cref="FeatureClient"/></returns>
141-
public FeatureClient GetClient(string name = null, string version = null, ILogger logger = null,
142-
EvaluationContext context = null) =>
145+
public FeatureClient GetClient(string? name = null, string? version = null, ILogger? logger = null,
146+
EvaluationContext? context = null) =>
143147
new FeatureClient(name, version, logger, context);
144148

145149
/// <summary>
@@ -200,7 +204,7 @@ public void AddHooks(IEnumerable<Hook> hooks)
200204
/// Sets the global <see cref="EvaluationContext"/>
201205
/// </summary>
202206
/// <param name="context">The <see cref="EvaluationContext"/> to set</param>
203-
public void SetContext(EvaluationContext context)
207+
public void SetContext(EvaluationContext? context)
204208
{
205209
this._evaluationContextLock.EnterWriteLock();
206210
try

src/OpenFeature/Error/FeatureProviderException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class FeatureProviderException : Exception
2020
/// <param name="errorType">Common error types <see cref="ErrorType"/></param>
2121
/// <param name="message">Exception message</param>
2222
/// <param name="innerException">Optional inner exception</param>
23-
public FeatureProviderException(ErrorType errorType, string message = null, Exception innerException = null)
23+
public FeatureProviderException(ErrorType errorType, string? message = null, Exception? innerException = null)
2424
: base(message, innerException)
2525
{
2626
this.ErrorType = errorType;

src/OpenFeature/Error/FlagNotFoundException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FlagNotFoundException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public FlagNotFoundException(string message = null, Exception innerException = null)
18+
public FlagNotFoundException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.FlagNotFound, message, innerException)
2020
{
2121
}

src/OpenFeature/Error/GeneralException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GeneralException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public GeneralException(string message = null, Exception innerException = null)
18+
public GeneralException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.General, message, innerException)
2020
{
2121
}

src/OpenFeature/Error/InvalidContextException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class InvalidContextException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public InvalidContextException(string message = null, Exception innerException = null)
18+
public InvalidContextException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.InvalidContext, message, innerException)
2020
{
2121
}

src/OpenFeature/Error/ParseErrorException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ParseErrorException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public ParseErrorException(string message = null, Exception innerException = null)
18+
public ParseErrorException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.ParseError, message, innerException)
2020
{
2121
}

src/OpenFeature/Error/ProviderNotReadyException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ProviderNotReadyException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public ProviderNotReadyException(string message = null, Exception innerException = null)
18+
public ProviderNotReadyException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.ProviderNotReady, message, innerException)
2020
{
2121
}

src/OpenFeature/Error/TargetingKeyMissingException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TargetingKeyMissingException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public TargetingKeyMissingException(string message = null, Exception innerException = null)
18+
public TargetingKeyMissingException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.TargetingKeyMissing, message, innerException)
2020
{
2121
}

src/OpenFeature/Error/TypeMismatchException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TypeMismatchException : FeatureProviderException
1515
/// </summary>
1616
/// <param name="message">Exception message</param>
1717
/// <param name="innerException">Optional inner exception</param>
18-
public TypeMismatchException(string message = null, Exception innerException = null)
18+
public TypeMismatchException(string? message = null, Exception? innerException = null)
1919
: base(ErrorType.TypeMismatch, message, innerException)
2020
{
2121
}

0 commit comments

Comments
 (0)