dsccommunity / DscResource.Common

This module contains common functions that are used in DSC resources.
https://dsccommunity.org
MIT License
9 stars 9 forks source link

`New-ErrorRecord`: New command #99

Closed johlju closed 7 months ago

johlju commented 1 year ago

Problem description

Suggest adding a new command that returns an ErrorObject. It can be re-used by all the commands New-*Exception commands in this module.

It would also help to return an ErrorObject when using Write-Error.

Verbose logs

n/a

How to reproduce

n/a

Expected behavior

Return an error record object.

Current behavior

Does not exist.

Suggested solution

By implementing issue #98 and what this issue suggest we could do:

Write-Error -ErrorRecord (New-ErrorRecord -Exception (New-InvalidOperationException -Message 'My message' -PassThru))

Operating system the target node is running

n/a

PowerShell version and build the target node is running

n/a

Module version used

n/a
johlju commented 1 year ago

This should take parameters

New-Object -TypeName 'System.Management.Automation.ErrorRecord' -ArgumentList = @(
    $Exception,
    $ErrorId
    $ErrorCategory,
    $TargetObject
)