Skip to content

Replace throw statements with ThrowTerminatingError in exception functions #177

@coderabbitai

Description

@coderabbitai

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

  • All exception functions use $PSCmdlet.ThrowTerminatingError() consistently
  • Existing functionality and error handling behavior preserved
  • Unit tests pass
  • Integration tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions