Skip to content

Fix null-handling errors in DHCP report generation#23

Merged
rebelinux merged 1 commit into
AsBuiltReport:devfrom
BitWise-0x:fix/null-handling-converters
Jun 16, 2026
Merged

Fix null-handling errors in DHCP report generation#23
rebelinux merged 1 commit into
AsBuiltReport:devfrom
BitWise-0x:fix/null-handling-converters

Conversation

@BitWise-0x

Copy link
Copy Markdown
Contributor

Summary

A DHCP report run against an environment with ~10 servers produced 700+ terminating errors in the verbose log while still completing. They trace to three null-handling defects.

Details

1. ConvertTo-TextYN / ConvertTo-EmptyToFiller throw on $null

Both declare [string] $TEXT with [AllowEmptyString()] but not [AllowNull()]. A $null argument is rejected by the parameter binder before the body runs:

TerminatingError(ConvertTo-TextYN): "Cannot process argument transformation on parameter 'TEXT'. Cannot convert value to type System.String."

The existing $Null { "--" } switch case is unreachable as a result. DHCP properties that legitimately return null (e.g. failover AutoStateTransition / EnableAuth, option-definition MultiValued) hit this and leave blank cells in the report. The failover ones surface in the log as (IPv4 Scope Failover Item) warnings. Adding [AllowNull()] lets null reach the body and render as --.

2. ConvertTo-HashToYN iterates the wrong variable

The loop enumerates $inObj, which is never defined in the function; it should enumerate the $TEXT parameter. As written the conversion loop does nothing.

3. Get-AbrADDHCPDomain calls Get-ADDomain before validating the domain

foreach ($Domain in ($OrderedDomains.split(" "))) can yield an empty element, and Get-ADDomain is called before the if ($Domain) guard:

TerminatingError(Get-ADDomain): "Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty." (DHCP Servers Section)

Guarding $Domain in the outer if (and testing $DomainInfo afterwards) skips the empty entry.

Changes

  • SharedUtilsFunctions.ps1 - add [AllowNull()] to ConvertTo-TextYN and ConvertTo-EmptyToFiller; fix ConvertTo-HashToYN to enumerate $TEXT
  • Get-AbrADDHCPDomain.ps1 - validate the domain value before Get-ADDomain, test $DomainInfo for the section guard
  • CHANGELOG.md - Unreleased / Fixed entries

Testing

ConvertTo-TextYN exercised against $null, '', ' ', 'True', 'False', and arbitrary text - null/empty/space now return --, booleans return Yes/No, and no terminating error is raised. Both changed files parse cleanly.

ConvertTo-TextYN and ConvertTo-EmptyToFiller declare their $TEXT
parameter as [string] with [AllowEmptyString()] but not [AllowNull()].
Passing $null tripped the parameter binder before the function body ran,
raising "Cannot process argument transformation on parameter 'TEXT'.
Cannot convert value to type System.String." The existing `$Null`
switch case was therefore unreachable. DHCP properties that come back
null (e.g. failover AutoStateTransition/EnableAuth, option-definition
MultiValued) produced these errors and left blank report cells.
Adding [AllowNull()] lets null reach the body and render as "--".

ConvertTo-HashToYN enumerated an undefined $inObj variable instead of
its $TEXT parameter, so it never converted the supplied hashtable.

Get-AbrADDHCPDomain called Get-ADDomain before testing the domain
value, so an empty element from $OrderedDomains.split(" ") raised
"Cannot validate argument on parameter 'Identity'. The Identity
property on the argument is null or empty." Guard the value first and
test the lookup result ($DomainInfo) instead.
@rebelinux

Copy link
Copy Markdown
Collaborator

Thank you for your contribution.

@rebelinux rebelinux merged commit ec0ed84 into AsBuiltReport:dev Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants