Description
Several functions in the source/Public directory use plain throw statements for terminating errors, which should be replaced with $PSCmdlet.ThrowTerminatingError() according to the DSC Community guidelines.
Background
This issue was identified during the review of PR #176 where New-Object usage was replaced with ::new() syntax. The refactoring revealed inconsistent error handling patterns that should be standardized.
Functions requiring updates
Based on code review, the following functions need to be updated to use $PSCmdlet.ThrowTerminatingError() instead of plain throw:
New-InvalidDataException (source/Public/New-InvalidDataException.ps1)
New-InvalidResultException (source/Public/New-InvalidResultException.ps1)
New-ObjectNotFoundException (source/Public/New-ObjectNotFoundException.ps1)
- Any other exception functions using plain
throw statements
Expected pattern
Replace patterns like:
throw (New-ErrorRecord @errorSplat)
With:
$PSCmdlet.ThrowTerminatingError((New-ErrorRecord @errorSplat))
Guidelines reference
From the DSC Community PowerShell Guidelines:
- Use
$PSCmdlet.ThrowTerminatingError() for terminating errors, use relevant error category
Related
Acceptance criteria
Description
Several functions in the
source/Publicdirectory use plainthrowstatements for terminating errors, which should be replaced with$PSCmdlet.ThrowTerminatingError()according to the DSC Community guidelines.Background
This issue was identified during the review of PR #176 where
New-Objectusage was replaced with::new()syntax. The refactoring revealed inconsistent error handling patterns that should be standardized.Functions requiring updates
Based on code review, the following functions need to be updated to use
$PSCmdlet.ThrowTerminatingError()instead of plainthrow:New-InvalidDataException(source/Public/New-InvalidDataException.ps1)New-InvalidResultException(source/Public/New-InvalidResultException.ps1)New-ObjectNotFoundException(source/Public/New-ObjectNotFoundException.ps1)throwstatementsExpected pattern
Replace patterns like:
With:
Guidelines reference
From the DSC Community PowerShell Guidelines:
$PSCmdlet.ThrowTerminatingError()for terminating errors, use relevant error categoryRelated
Acceptance criteria