Fix NRT errors and enable TreatWarningsAsErrors#46
Conversation
- Enable TreatWarningsAsErrors in build - Fix nullable reference annotations in Aliyun storage implementation
There was a problem hiding this comment.
Pull request overview
Updates the Aliyun storage provider and build configuration to support stricter compilation (warnings as errors) by addressing nullable-reference-type (NRT) warnings and aligning dependency versions.
Changes:
- Bumped
Foundatio/Foundatio.TestHarnesspackage references to13.0.0-beta3.35. - Adjusted Aliyun storage/provider option and connection-string builder nullability annotations.
- Minor internal refactors related to nullability initialization.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Directory.Build.props | Updates Foundatio.TestHarness package version. |
| src/Foundatio.Aliyun/Foundatio.Aliyun.csproj | Updates Foundatio package version. |
| src/Foundatio.Aliyun/Storage/AliyunFileStorageOptions.cs | Changes ConnectionString nullability/initialization. |
| src/Foundatio.Aliyun/AliyunConnectionStringBuilder.cs | Changes connection-string parts (Endpoint, AccessKey, SecretKey) nullability + ctor signature. |
| src/Foundatio.Aliyun/Storage/AliyunFileStorageConnectionStringBuilder.cs | Changes _bucket init and ctor signature nullability. |
| src/Foundatio.Aliyun/Storage/AliyunFileStorage.cs | Updates SearchCriteria.Prefix initialization for NRT. |
Comments suppressed due to low confidence (1)
src/Foundatio.Aliyun/AliyunConnectionStringBuilder.cs:20
- Changing the constructor parameter from
string?tostringis a source-breaking nullability change for any consumers/derivers that may currently passnull(even though it throws at runtime). If you want to preserve compatibility while still validating, consider keeping thestring?signature (or adding an overload) and continuing to throw for null/empty input.
protected AliyunConnectionStringBuilder() { }
protected AliyunConnectionStringBuilder(string connectionString)
{
if (String.IsNullOrEmpty(connectionString))
throw new ArgumentNullException(nameof(connectionString));
Parse(connectionString);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public string Endpoint { get; set; } = null!; | ||
|
|
||
| public string? AccessKey { get; set; } | ||
| public string AccessKey { get; set; } = null!; | ||
|
|
||
| public string? SecretKey { get; set; } | ||
| public string SecretKey { get; set; } = null!; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| public class AliyunFileStorageOptions : SharedOptions | ||
| { | ||
| public string? ConnectionString { get; set; } | ||
| public string ConnectionString { get; set; } = null!; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
|
|
||
| public AliyunFileStorageConnectionStringBuilder(string? connectionString) : base(connectionString) | ||
| public AliyunFileStorageConnectionStringBuilder(string connectionString) : base(connectionString) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Address PR review comments: properties annotated as non-nullable string were initialized with null!, making the nullability contract inaccurate. Initialize with string.Empty instead so the non-nullable annotation is truthful at runtime.
…ring.Empty Tests assert null for unset properties. Using string.Empty changed the semantic meaning of not-set from null to empty, breaking 3 tests. Properly nullable properties preserve original behavior.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _logger = options.LoggerFactory?.CreateLogger(GetType()) ?? NullLogger.Instance; | ||
|
|
||
| if (String.IsNullOrEmpty(options.ConnectionString)) | ||
| throw new ArgumentException("ConnectionString is required.", nameof(options)); |
There was a problem hiding this comment.
The ArgumentException uses nameof(options) as the parameter name, but the invalid value is options.ConnectionString. Using nameof(options.ConnectionString) will make the exception’s ParamName accurate and improve diagnosability.
| throw new ArgumentException("ConnectionString is required.", nameof(options)); | |
| throw new ArgumentException("ConnectionString is required.", nameof(options.ConnectionString)); |
| private class SearchCriteria | ||
| { | ||
| public string Prefix { get; set; } = String.Empty; | ||
| public string Prefix { get; set; } = null!; |
There was a problem hiding this comment.
Prefix is initialized with null!, which makes the non-nullable contract less truthful and can allow a null value if SearchCriteria is ever instantiated without setting Prefix. Initializing it to String.Empty (as before) avoids the null-forgiving operator and keeps it safe by default.
| public string Prefix { get; set; } = null!; | |
| public string Prefix { get; set; } = String.Empty; |
Summary
Test plan