Fix null-handling errors in DHCP report generation#23
Merged
rebelinux merged 1 commit intoJun 16, 2026
Conversation
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.
Collaborator
|
Thank you for your contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-EmptyToFillerthrow on$nullBoth declare
[string] $TEXTwith[AllowEmptyString()]but not[AllowNull()]. A$nullargument is rejected by the parameter binder before the body runs:The existing
$Null { "--" }switch case is unreachable as a result. DHCP properties that legitimately return null (e.g. failoverAutoStateTransition/EnableAuth, option-definitionMultiValued) 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-HashToYNiterates the wrong variableThe loop enumerates
$inObj, which is never defined in the function; it should enumerate the$TEXTparameter. As written the conversion loop does nothing.3.
Get-AbrADDHCPDomaincallsGet-ADDomainbefore validating the domainforeach ($Domain in ($OrderedDomains.split(" ")))can yield an empty element, andGet-ADDomainis called before theif ($Domain)guard:Guarding
$Domainin the outerif(and testing$DomainInfoafterwards) skips the empty entry.Changes
SharedUtilsFunctions.ps1- add[AllowNull()]toConvertTo-TextYNandConvertTo-EmptyToFiller; fixConvertTo-HashToYNto enumerate$TEXTGet-AbrADDHCPDomain.ps1- validate the domain value beforeGet-ADDomain, test$DomainInfofor the section guardCHANGELOG.md- Unreleased / Fixed entriesTesting
ConvertTo-TextYNexercised 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.