Repository navigation
Enable nullable reference types in DacpacTool - #1046
Conversation
DacpacTool used <Nullable>warnings</Nullable>. It now uses enable, and the 66 warnings this gives are fixed by annotating what can be null: - options that DotMake.CommandLine leaves unset are nullable; the required ones (--name, --input, --targetServerName, --targetDatabaseName) keep non-nullable types; - PackageBuilder.Model and Metadata are nullable until UsingVersion and SetMetadata, with MemberNotNull on the Ensure* checks and ValidateModel; - reflection results, the Get*Script extensions and optional parameters that are already checked for null are annotated. Program checks --output with ThrowIfNull before saving, which SaveToDisk did first anyway. Tests that read Model, Metadata and the scripts use ! so they build without warnings whether or not their project enables nullable. Fixes rr-wfm#1030 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@menes97 You are on fire - thanks so much for these targeted PRs |
| { | ||
| [CliOption(Description = "Name of the package", Required = true, Name = "--name", Alias = "-n")] | ||
| public string Name { get; set; } | ||
| public string Name { get; set; } = null!; |
| { | ||
| [CliOption(Description = "Path to the .dacpac package to deploy", Required = true, Name = "--input", Alias = "-i")] | ||
| public FileInfo Input { get; set; } | ||
| public FileInfo Input { get; set; } = null!; |
There was a problem hiding this comment.
Could it be the "required" keword iso null! ?
|
|
||
| [CliOption(Description = "Reference(s) to include", Required = false, Name = "--reference", Alias = "-r")] | ||
| public string[] Reference { get; set; } | ||
| public string[]? Reference { get; set; } |
There was a problem hiding this comment.
Perhaps we should initialize these array arguments to empty arrays rather than making them nullable? Then wherever we're reading them we don't have to check for null
|
@menes97 could you merge this with the latest master |
…cpactool # Conflicts: # src/DacpacTool/VersionChecker.cs
|
@menes97 Can you have a look at the open comments? |
Required options use the `required` modifier instead of `= null!`, and the array options start as empty arrays, so the null checks where they are read are gone. SqlCmdVariables are still only added when some are given. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Done in 5751228: the required options use |
|
@menes97 Thank you for your contribution |
Fixes #1030
DacpacToolused<Nullable>warnings</Nullable>. This switches it toenableand fixes the 66 warnings that gives, by annotating what can actually be null rather than suppressing:Version,Output,Reference,PreDeploy,TargetUser, ...). Options markedRequired = true(--name,--input,--targetServerName,--targetDatabaseName) keep non-nullable types with= null!, since the parser always sets them.PackageBuilder.Model/Metadataare nullable untilUsingVersion/SetMetadata(andModelagain afterDispose).EnsureModelCreated,EnsureMetadataCreatedandValidateModelcarry[MemberNotNull], so code after them needs no!.externalParts, the pre/post scripts ofAddOutputArtifactsandAddScript,suppressionList,rulesExpression, the password ofUseSqlAuthentication(prompted when empty), thesourceof the batchFormatextensions, theversionofSetMetadata.GetPreDeploymentScript/GetPostDeploymentScript/GetPrePlanScript,IConsole.ReadLine,SetDeployProperty, and the reflection lookups.Behaviour stays the same, with two small exceptions in paths that shouldn't happen:
BuildDacpaccallsArgumentNullException.ThrowIfNull(options.Output)beforeSaveToDisk, which did exactly that as its first statement.CreateDacModelErrorreturns noDacModelError,GetModelValidationErrorsthrows anInvalidOperationExceptionwith a message instead of the constructor'sArgumentNullException.nulllogs empty instead of throwing aNullReferenceException.The tests that read
Model,Metadataand the scripts (PackageBuilderTests,ExtensionsTest,ReferencedDeploymentScriptTests) use!there. They build without warnings both on master and with #1044 merged in. I checked both combinations locally, and they merge without conflicts.Checks
dotnet buildof the solution: noCSwarnings. The remaining warnings are the existingEnableGenerateDocumentationFileand NuGet audit ones.DacpacTool.Tests(net8.0, net9.0, net10.0): 239 of 240 pass.AddInputFile_FileExists_WithInvalidSyntaxfails on master as well on my machine, because it compares a parser message under a Turkish locale.The second bullet of the issue suggests a repository-wide
<Nullable>enable</Nullable>inDirectory.Build.props. I left that out to keep this change to DacpacTool. It can follow once the test projects are all enabled.🤖 Generated with Claude Code