-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
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
- PR: PS 5.0 required; replace New-Object with ::new(); streamline errors #176
- Comment: PS 5.0 required; replace New-Object with ::new(); streamline errors #176 (comment)
- Requested by: @dan-hughes
Acceptance criteria
- All exception functions use $PSCmdlet.ThrowTerminatingError() consistently
- Existing functionality and error handling behavior preserved
- Unit tests pass
- Integration tests pass
Metadata
Metadata
Assignees
Labels
No labels